I have a edit text and button
EditText edit=(EditText) findViewById(R.id.edittext);
Button btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
Toast.makeText(context,edit.getText().toString(),Toast.LENGTH_SHORT).show();
edit.setText("hello");
}
}
but when i click the button i can get the toast with "hello"(the text of the edittext) but the edittext is empty. is it a bug?
(edit) this is my full code finding = (EditText) rowView.findViewById(R.id.txtfindings); finding.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new AlertDialog.Builder(context)
.setTitle("Findings")
.setMultiChoiceItems(
CustomDialog.service.getFindingsArray(), // array of string ex(cd,hard drive,motherboard)
_selectionsFindings, // boolean array size=size of findingsarray
new DialogSelectionClickHandler()) // set click handler on checkbox
.setPositiveButton("OK",
new DialogButtonClickHandler() //set button click
).create()
.show();
}
});
public class DialogSelectionClickHandler implements
DialogInterface.OnMultiChoiceClickListener {
public void onClick(DialogInterface dialog, int clicked,boolean selected) {
} }
public class DialogButtonClickHandler implements
DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int clicked) {
switch (clicked) {
case DialogInterface.BUTTON_POSITIVE:
printSelectedFinding();//call the function
break;
}
}
}
protected void printSelectedFinding() {
String textfinding = "";
ArrayList<String> values = new ArrayList<String>(Arrays.asList(finding
.getText().toString().split(",")));
if (!finding.getText().toString().equalsIgnoreCase("")) {
if (!finding.getText().toString().substring(finding.getText().toString().length() - 1,
finding.getText().toString().length()).equalsIgnoreCase(",")) {
textfinding = ","; //check if last character is == ,
}
}
for (int i = 0; i < CustomDialog.service.getFindingsArray().length; i++) {
if (_selectionsFindings[i] //check which item is checked
&& !values.contains(CustomDialog.service.getFindingsArray()[i].trim())) { // check if edittext contains the text
textfinding += CustomDialog.service.getFindingsArray()[i] + ","; // concatinate string
}
}
finding.append(textfinding); // this where error happens finding is an edittext ex(textfinding = hard drive) finding should have "hard drive"
// but it is not displayed but when i use getText() i can get "hard drive"
}