0
我做了一個關於ListFragment的演示,但它是錯誤的。我能做什麼?誰幫我修復它。我研究Android的一個月所以不是很好的技能演示ListFragment錯誤
ListFragment.Class
onCreateView{
MenuAdapter adapter = new MenuAdapter(getActivity());
menu = new Menu(R.drawable.ic_home, "Trang Chu");
adapter.add(menu);
menu = new Menu(R.drawable.ic_people, "Khuyen Mai");
adapter.add(menu);
menu = new Menu(R.drawable.ic_photos, "Cam Nang");
adapter.add(menu);
menu = new Menu(R.drawable.ic_communities, "Gan Toi");
adapter.add(menu);
menu = new Menu(R.drawable.ic_pages, "Video");
adapter.add(menu);
menu = new Menu(R.drawable.ic_whats_hot, "Gioi Thieu RedSun");
adapter.add(menu);
setListAdapter(adapter);
return inflater.inflate(R.layout.list, null);
}
在我的適配器,
ArrayAdapter<Menu> {
Context context;
public MenuAdapter(Context context) {
super(context, 0);
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = LayoutInflater.from(getContext()).inflate(
R.layout.menulist_layout, null);
}
ImageView icon = (ImageView) view.findViewById(R.id.menuItem);
icon.setImageResource(getItem(position).getImageRes());
TextView title = (TextView) view.findViewById(R.id.menuText);
title.setText(getItem(position).getTitle());
return view;
}
}
我沒有在這個代碼知道什麼錯誤。
究竟是什麼錯誤?你能編譯? – Libin