我正在使用android中的片段,我正在扩展androID.app.ListFragment以显示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方法中返回所需类型的VIEw.在这方面,ListActivity和ListFragment之间几乎没有任何区别.
总结以上是内存溢出为你收集整理的android – 使用listactivity扩展片段全部内容,希望文章能够帮你解决android – 使用listactivity扩展片段所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)