我正在尝试将字符串添加到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));
}
}
});
这是我得到的错误:
答案 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不是上下文。