Android:无法解析getViewById()

时间:2015-04-23 20:49:55

标签: android

这是需要获取另一个xml文件中定义的AutoCompleteTextView的findViewById的函数,其中id = suggestionsTextView

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();



        }
    }
}

我得到的错误无法解决findViewById问题。没有可用的修复程序。请帮忙。

1 个答案:

答案 0 :(得分:0)

private void updateCandidates(Activity context) {

}

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

context.findViewById(Some ID Here)