我设计了一个包含列表视图的警告对话框。我只想在单击项目时启用对话框的正按钮,否则禁用它。点击后我无法启用该按钮。在下面找到我的代码:
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();
}
有人请指导我。
答案 0 :(得分:0)
int listItem;