当我使用此自定义ListView适配器单击menuButton时,我得到的是AndroidRuntimeException:
public class MenuAdapter extends ArrayAdapter<Menu>{
private List<Menu> menus;
public MenuAdapter(Context context, int textViewResourceId, List<Menu> menus){
super(context, textViewResourceId, menus);
this.menus = menus;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View menuView = convertView;
if (menuView == null){
LayoutInflater menuViewInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
menuView = menuViewInflater.inflate(R.layout.menu_row, null);
}
Menu menu = menus.get(position);
if (menu != null) {
Button menuButton = (Button)menuView.findViewById(R.id.menu_name);
menuButton.setText(menu.name);
menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent menuIntent = new Intent(v.getContext(), MenuActivity.class);
v.getContext().startActivity(menuIntent);
}
});
}
return menuView;
}
}
任何想法我做错了什么?
答案 0 :(得分:0)
不确定你尝试用v.getContext()做什么。尝试类似下面的内容
final Intent intent = new Intent(this, MenuActivity.class);
startActivityForResult(intent);
或
startActivity(new Intent("Your.Package.name.classnameinManifest"));