Android:无法解析getViewById()

Android:无法解析getViewById(),android,Android,此函数需要获取在另一个id为suggestionsTextView的xml文件中定义的AutoCompleteTextView的findViewById private void updateCandidates() { if (!mCompletionOn) { if (mComposing.length() > 0) { list = new ArrayList<String>(); ArrayList

此函数需要获取在另一个id为suggestionsTextView的xml文件中定义的AutoCompleteTextView的findViewById

private void updateCandidates() {
    if (!mCompletionOn) {
        if (mComposing.length() > 0) {
            list = new ArrayList<String>();
            ArrayList<String> list1 = new ArrayList<String>();
            //  list.add(mComposing.toString());
            String asd = mComposing.toString();
            asd = asd.trim();


            DBManager db;
            db=new DBManager(getApplicationContext());
            db.open();
            Cursor c = db.suggest(asd);

            AutoCompleteTextView t = (AutoCompleteTextView)findViewById(R.id.suggestionsTextView);



            if(c!=null)
            {
                if(c.moveToFirst()) {
                    StringBuilder str = new StringBuilder();
                    String text1 = c.getString(c.getColumnIndex("word"));
                    str.append(text1).append("\n");
                    String text = c.getString(c.getColumnIndex("gremeaning"));
                    String arr[] = text.split(";");
                    for (String a : arr) {
                        a = a.trim();
                        System.out.println(a);

                        Toast.makeText(getApplicationContext(), "This is the word = " + a, Toast.LENGTH_SHORT).show();
                        list.add(a);
                        str.append(a).append("\n");


                    }

                    t.setText(str);
                }


                }c.close();



        }
    }
}
private void updateCandidates(){
如果(!mCompletionOn){
如果(mComposing.length()>0){
列表=新的ArrayList();
ArrayList list1=新的ArrayList();
//添加(mComposing.toString());
字符串asd=mComposing.toString();
asd=asd.trim();
数据库管理器数据库;
db=新的DBManager(getApplicationContext());
db.open();
光标c=db.suggest(asd);
AutoCompleteTextView t=(AutoCompleteTextView)findViewById(R.id.suggestionsTextView);
如果(c!=null)
{
if(c.moveToFirst()){
StringBuilder str=新的StringBuilder();
字符串text1=c.getString(c.getColumnIndex(“word”);
str.append(text1.append(“\n”);
String text=c.getString(c.getColumnIndex(“gremeans”);
字符串arr[]=text.split(“;”);
for(字符串a:arr){
a=a.修剪();
系统输出打印项次(a);
Toast.makeText(getApplicationContext(),“这是单词=“+a,Toast.LENGTH\u SHORT).show();
列表.添加(a);
str.append(a).append(“\n”);
}
t、 setText(str);
}
}c、 close();
}
}
}
我遇到的错误是无法解析findViewById。没有可用的修复程序。请帮忙

private void updateCandidates(Activity context) {

}
您需要在这个函数中获取活动的上下文,然后必须按如下方式调用

context.findViewById(Some ID Here)

解决了这个问题。但是,此函数updateCandidates()已被多次调用。我应该传递什么参数?创建静态类作为follow公共类Utils{public static Activity context;},然后在MainActivity onCreate方法Utils.context=this;现在调用findViewById,如下所示:Utils.context.findViewById(此处的一些ID)您的“updateCandidates”方法在哪里?在活动中?你在使用碎片吗?