fragment显示不出listview 10
publicclassSlidingFragmentextendsFragment{privateListViewlistView;privateContextconte...
public class SlidingFragment extends Fragment {
private ListView listView;
private Context context;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.sliding_menu_menu, container,
false);
listView = (ListView) view.findViewById(R.id.list_menu);
List<Map<String, Object>> list = getMenuResource();
return view;
}
public static List<Map<String, Object>> getMenuResource() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("image", R.drawable.myfriend);
map.put("text", "我的好友");
list.add(map);
Map<String, Object> map1 = new HashMap<String, Object>();
map.put("image", R.drawable.mylove);
map.put("text", "我的收藏");
list.add(map1);
Map<String, Object> map2 = new HashMap<String, Object>();
map.put("image", R.drawable.mysms);
map.put("text", "我的消息");
list.add(map2);
return list;
}
}
在return view前面少写了一段:
SimpleAdapter simpleAdapter = new SimpleAdapter(context,
list, R.layout.list_menu_item,
new String[] { "image", "text" }, new int[] { R.id.imageview,
R.id.textview });
listView.setAdapter(simpleAdapter); 展开
private ListView listView;
private Context context;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.sliding_menu_menu, container,
false);
listView = (ListView) view.findViewById(R.id.list_menu);
List<Map<String, Object>> list = getMenuResource();
return view;
}
public static List<Map<String, Object>> getMenuResource() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("image", R.drawable.myfriend);
map.put("text", "我的好友");
list.add(map);
Map<String, Object> map1 = new HashMap<String, Object>();
map.put("image", R.drawable.mylove);
map.put("text", "我的收藏");
list.add(map1);
Map<String, Object> map2 = new HashMap<String, Object>();
map.put("image", R.drawable.mysms);
map.put("text", "我的消息");
list.add(map2);
return list;
}
}
在return view前面少写了一段:
SimpleAdapter simpleAdapter = new SimpleAdapter(context,
list, R.layout.list_menu_item,
new String[] { "image", "text" }, new int[] { R.id.imageview,
R.id.textview });
listView.setAdapter(simpleAdapter); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询