我想要用長按選單來切換頁面,但是我呼叫MainActivity裡面切換的程式就閃退了
lvAlarmlist.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
new AlertDialog.Builder(getContext()).setTitle("操作選項").setItems(new CharSequence[]{"刪除","修改"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
deleteAlarm(position);
break;
case 1:
MA.SetAlarm();
break;
default:
break;
}
}
}).setNegativeButton("取消",null).show();
return true;
}
});
}
private MainActivity MA;
選單部分,case 1的地方
public void SetAlarm(){
System.out.println("1");
//Intent intent = new Intent();
//intent.setClass(MainActivity.this,SetAlarm.class);
//startActivity(intent);
}
MainActivity裡面的部分,經過實驗 一呼叫就爆炸