gpt4 book ai didi

android - setListAdapter 不适用于 fragment ?任何替代品

转载 作者:行者123 更新时间:2023-11-30 03:10:20 25 4
gpt4 key购买 nike

    protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
getActivity().runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */


ListAdapter adapter = new SimpleAdapter(
getActivity(), inboxList,
R.layout.inbox_list_item, new String[] { TAG_LINK, TAG_SUBJECT },
new int[] { R.id.link, R.id.subject });
// updating listview
lv.setListAdapter(adapter);

lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

Toast.makeText(getActivity(),
"You clicked on feed "+position, Toast.LENGTH_LONG).show();



}

});

}
});

}

我试图在 fragment Activity 中获取 ListView 。此 ListView 是从 JSON 对象解析而来的。此代码在 fragment 中运行。但是,setlistadapter 会报错。 setlistadapter 的任何替代方案以及如何实现它。谢谢。

最佳答案

像这样使用自定义适配器:

Listview list = (Listview)findviewbyId(R.id.list);
SearchListAdapter adapter = new SearchListAdapter(this,
getActivity(), rowItems(your data to inflate in adapter));
lis.setAdapter(adapter);

关于android - setListAdapter 不适用于 fragment ?任何替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21107287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com