使用ArrayAdapter for ListView给出错误

时间:2011-12-25 05:10:56

标签: java android listview android-arrayadapter

我正在尝试将字符串添加到ListView中,并在另一个ListView内调用(更改OnItemClickListener内的ContentView)

以下是代码:

 lv1.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
            long arg3) {
        // TODO Auto-generated method stub

        if(lv1.getItemAtPosition(pos).equals(cat[0]))                                                       
        {                                                                                                           
            setContentView(R.layout.browse_engineering);
            final ListView engList = (ListView)findViewById(R.id.eng_list);
            engList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,eng_build));


        }                                                                                                                                                                                                     
    }
 });

这是我得到的错误:

Error image.

1 个答案:

答案 0 :(得分:3)

替换此

engList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,eng_build));

由此,

engList.setAdapter(new ArrayAdapter<String>(yourActivity.this,android.R.layout.simple_list_item_1,eng_build));

因为onItemClickListners不是上下文