I have opened a custom dialog inside longPress of a button, Inside that custom dialog i have two buttons and one edit text. I want to change the name of the button which i have longpressed with the name which i get from the edit text inside the custom dialog, the buttons are not working.
public void initializeLPButtons(Button[] btns, int[] rArrays) {
for(i=0; i<btns.length; i++) {
btns[i] = (Button) findViewById(rArrays[i]);
btns[i].setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
renameBtn();
return true;
}
});
}
}
public void renameBtn() {
final AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setView(R.layout.dialog_renamebtn);
dialog.setTitle("Rename Button...");
dialog.setMessage("Rename The Button To:");
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
final View dialogView = inflater.inflate(R.layout.dialog_renamebtn, null);
renameEt = (EditText) dialogView.findViewById(R.id.renameEt);
renameBtn = (Button) dialogView.findViewById(R.id.renameBtn);
cnclRenameBtn = (Button) dialogView.findViewById(R.id.cnlRenameBtn);
cnclRenameBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
renameBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
renameBtnTxt();
}
});
dialog.show();
}
public void renameBtnTxt() {
if (renameEt.getText().toString().length() > 0) {
btns[i].setText(renameEt.getText().toString());
}else {
Toast.makeText(MainActivity.this, "Please choose a name.",
Toast.LENGTH_SHORT).show();
}
}
I dont think my code has problems. Please if it is something with java help me find it.