顯示我有以下類:DialogFragment不上按一下按鈕
public class MyAlertDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
// Set Dialog Icon
.setIcon(R.drawable.ic_launcher)
// Set Dialog Title
.setTitle("Alert DialogFragment")
// Set Dialog Message
.setMessage("Alert DialogFragment Tutorial")
// Positive button
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do something else
}
})
// Negative Button
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do something else
}
}).create();
}
}
,並從中我打電話這個類的其他類。
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<?> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<?> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
....
}
....
....
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final Button btn_login = (Button)convertView.findViewById(R.id.btn_login);
btn_print.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new LineupFragment();
}
});
return convertView;
}
public class LineupFragment extends FragmentActivity{
public LineupFragment() {
MyAlertDialogFragment alert = new MyAlertDialogFragment();
alert.show(getSupportFragmentManager(), "Alert_Dialog");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
}
當我點擊按鈕,然後它給出了強制關閉錯誤。
FATAL EXCEPTION: main
Process: com.novum.ideal, PID: 9408
java.lang.IllegalStateException: Activity has been destroyed
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1387)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:636)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:615)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:138)
at com.novum.ideal.ExpandableListAdapter$LineupFragment.<init>(ExpandableListAdapter.java:149)
at com.novum.ideal.ExpandableListAdapter$1.onClick(ExpandableListAdapter.java:126)
at android.view.View.performClick(View.java:4463)
at android.view.View$PerformClick.run(View.java:18770)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
我想只顯示來自這個類的對話框。
我該如何解決它?
你不需要我有'oncreate'加入LineupFragment – Eoin