我正在开发Android片段中的ListView。该类扩展了ListFragment。不能在ListFragment上使用SimpleAdapter
我试着用这个例子: http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/
但问题是,如果类扩展ListFragment,将其改为ListActivity将使SimpleAdapter的工作,构造SimpleAdapter没有定义,但随后申请不会。
下面的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View tmp_view = inflater.inflate(R.layout.clients_list, container, false);
ListView list = (ListView) tmp_view.findViewById(R.id.list);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("train", "101");
map.put("from", "6:30 AM");
map.put("to", "7:40 AM");
mylist.add(map);
map = new HashMap<String, String>();
map.put("train", "103(x)");
map.put("from", "6:35 AM");
map.put("to", "7:45 AM");
mylist.add(map);
// ...
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.clients_list_item,
new String[] {"train", "from", "to"}, new int[] {R.id.TRAIN_CELL, R.id.FROM_CELL, R.id.TO_CELL});
list.setAdapter(mSchedule);
ListFragment.setListAdapter(mSchedule);
return tmp_view;
}
所以我不会有任何问题,如果这是一个活动,但它是一个片段:S任何解决方案?
更换
你有一组一个适配器已经,尝试删除ListFragment.setListAdapter(mSchedule);这条线。 –
我知道,只是尝试的东西,顺便说一句问题是在SimpleAdapter行。构造函数未定义。我想解决这个问题,设置列表适配器是好的。谢谢btw。 – Michelh91