我正在使用警报对话框(setmultichioceitems()),并且当用户单击按钮时正在使用按钮,所有复选框均会自动标记。
但要在markall按钮中写些什么,以便只需单击即可选中所有复选框。
这是我的代码。
AlertDialog.Builder attendance = new AlertDialog.Builder(this);
attendance.setTitle("MARK ATTENDANCE");
attendance.setIcon(R.drawable.markattendeanceicon);
attendance.setMultiChoiceItems(l, A, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int position, boolean isChecked) {
if(isChecked)
{
TastyToast.makeText(AdminPanel.this,"attendance marked of "+l[position],TastyToast.SUCCESS,TastyToast.LENGTH_LONG).show();
}
}
});
attendance.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
TastyToast.makeText(AdminPanel.this,"your record is saved",TastyToast.INFO,TastyToast.LENGTH_LONG).show();
}
});
attendance.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
attendance.setNeutralButton("MarkAll", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
attendance.setCancelable(false);
attendance.show();
答案 0 :(得分:0)
您可以将<RelativeLayout>
<spinner/>
<button/>
<whatever/>
</RelativeLayout>
用于此目的。当您单击对话框按钮以选中所有复选框。取一个sharedpreferences
变量并将其设为boolean
。
true
现在在attendance.setNeutralButton("MarkAll", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// put sharedprefence value as true/false or 0/1
SharedPreferences sharedPreferences = getSharedPreferences("myData", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("checkboxes", true);
editor.commit();
}
});
里面,您拥有所有activity
的调用checkboxes
方法。
override