我設計了一個包含列表視圖的警報對話框。我只想在單擊某個項目時啓用對話框的正面按鈕,否則請將其禁用。點擊後我無法啓用按鈕。找到我的代碼如下:啓用/禁用項目點擊對話框按鈕
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = (View)inflater.inflate(R.layout.action_list, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setTitle("Select any action");
alertDialogBuilder.setView(view);
alertDialogBuilder.setInverseBackgroundForced(true);
actionLV = (ListView)view.findViewById(R.id.action_list);
actionLV.setAdapter(new ActionListAdapter(actionAL,getActivity()));
alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which) {
// Write your code here to invoke YES event
Toast.makeText(getActivity().getApplicationContext(), "You clicked on Cancel",
Toast.LENGTH_SHORT).show();
}
});
alertDialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(getActivity(),LogItActivity.class);
intent.putExtra("ACTION_NAME", ActionListAdapter.checkedActionName);
startActivity(intent);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
if(ActionListAdapter.checkedActionName != null){
done.setEnabled(true);
}
}
});
alertDialog.show();
done = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
done.setEnabled(false);
if(ActionListAdapter.checkedActionName!= null){
alertDialog.show();
}
有人請指導我。
哪裏是你的ListView項單擊監聽器? – Riser 2014-11-24 07:41:13
其內部適配器 – megha 2014-11-24 07:42:20
我啓用了適配器類中的按鈕,點擊偵聽器。它的工作 – megha 2014-11-24 08:18:17