我有一些按钮,比如 btnA1、btnA2、btnA3,我希望用户可以在长按时更改按钮文本。当用户长按任何按钮时,它会为用户提供对话框以填充按钮文本和一些 textView。这是我的代码:
btnA1.setOnLongClickListener(new Button.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
dialogForm();
return true;
}
});
这是 dialogForm 函数:
private void dialogForm(){
dialog = new AlertDialog.Builder(MainActivity.this);
inflater = getLayoutInflater();
dialogView = inflater.inflate(R.layout.macro_form, null);
dialog.setView(dialogView);
dialog.setCancelable(true);
dialog.setIcon(R.mipmap.ic_launcher);
dialog.setTitle("Macro Form");
txtMacroName = (EditText) dialogView.findViewById(R.id.txtMacroName);
txtMacroStatus = (EditText) dialogView.findViewById(R.id.txtMacroValue);
dialog.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
macroName = txtMacroName.getText().toString();
macroStatus = txtMacroStatus.getText().toString();
dialog.dismiss();
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
}
我如何检测在对话框dismiss()之前按下了哪个按钮,只有那个按钮会改变;
元芳怎么了
慕的地8271018
相关分类