开发者

How to change listview adapter in section setOnItemClickListener

I have listview with some listadapter after click on item from list I'd like to reload list with new data, change adapter's contests.

I use this in setOnItemClickListener, but I get error: "Type The constructor ArrayAdapter(new AdapterView.OnItemClickListener(){}, int, ArrayList) is undefined"

开发者_开发知识库
list.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_1,Data.user.getChosen_rest()));

How should I do this correctly?


Glendon's answer is probably the right one. Nevertheless, in case you really need to change the adapter for some reason, you need to pass the right Context instance to the first argument of the constructor.

You can extend OnClickListener and add a field mContext to it, to which you will assign the current Activity. Then , use it as:

list.setAdapter(new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1,Data.user.getChosen_rest()));

Alternatively, if the listener is an inner class of the Activity, you can use:

list.setAdapter(new ArrayAdapter<String>(MyActivity.this, R.layout.simple_list_item_1,Data.user.getChosen_rest()));


The answer here should get you headed in the right direction. If you can transform your initial ArrayAdapter using add(), remove(), insert(), or clear(), you can call notifyDataSetChanged() to reload it.

Edit

Actually, to better address your error, try replacing

list.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_1,Data.user.getChosen_rest()));

with

list.setAdapter(new ArrayAdapter<String>(NameOfActivity.this, R.layout.simple_list_item_1,Data.user.getChosen_rest()));

first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜