gpt4 book ai didi

android - 使用 listactivity 扩展 Fragments

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:05 25 4
gpt4 key购买 nike

我正在使用 android 中的 fragment ,正在扩展 android.app.ListFragment 以显示 ListView ,但它只需要 ListView 中的一个项目。我想在 ListView 中显示 2 个项目,它可以扩展 ListActivity 类,但我想扩展 fragment 和 listactivty。
Refer this image

public class ListFragmentnewforel extends android.app.ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

ArrayList<HashMap<String, String>> list = buildData();
String[] from = { "purpose" , "name","desc", "num"};
int[] to = { R.id.detailsText1, R.id.detailsText2, R.id.detailsText3, };

SimpleAdapter adapter = new SimpleAdapter(this, list,R.layout.mylistview,from,to);
setListAdapter(adapter);
}


public void onListItemClick(ListView l, View v, int position, long id) {
ArrayList<String>arr=new ArrayList<String>();
String item = (String) getListAdapter().getItem(position);
DetailFragment fragment = (DetailFragment) getFragmentManager()
.findFragmentById(R.id.detailFragment);
if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
fragment.setText(item);
}
else {
Intent intent = new Intent(getActivity().getApplicationContext(),
DetailActivity.class);
Xmlparsingactiforele d=new Xmlparsingactiforele();
arr=d.myelarraylist(item);
// arr.get(0);
intent.putExtra("value1", arr.get(0));
intent.putExtra("value2", arr.get(1));
intent.putExtra("value3", arr.get(2));
intent.putExtra("value4", arr.get(3));
startActivity(intent);

}

}
private ArrayList<HashMap<String, String>> buildData() {
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
list.add(putData("Android", "Mobile","two", "1"));
list.add(putData("Windows7", "Windows7","one", "2"));
list.add(putData("iPhone", "iPhone","three", "3"));
return list;
}

private HashMap<String, String> putData(String name, String purpose,String a, String n) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", name);
item.put("purpose", purpose);
item.put("desc", a);
item.put("num", n);

return item;
}
}

最佳答案

没有什么能阻止您在 ListView 项目中显示您想要的任何内容。请阅读ListFragment的API文档.

您可以创建一个 ListAdapter,它在其 getView 方法中返回您想要的类型的 ViewListActivityListFragment 在这方面几乎没有什么区别。

关于android - 使用 listactivity 扩展 Fragments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12386748/

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