Reputation: 1
I would like to know how I can get text that is in a EditText after I click a button, and this value is stored in a new variable, clear my EditText, and perform the same action again, so storing the values on different variables, and then perform a calculation, my big question is to store each value in a variable for different time, appreciate if someone can help! Thank you.
Upvotes: 0
Views: 83
Reputation: 133560
ArrayList listString = new ArrayList();
Button myButton = (Button)findViewById(R.id.BUTTON_ID);
EditText myEditText = (EditText)findViewById(R.id.EDITTEXT_ID);
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
listString.add(myEditText.getText().toString());
myEditText.setText("");
}
});
Get String Values
for(int i=0;i<listString.size();i++)
{
System.out.println("String values..."+listString.get(i).toString());
}
Upvotes: 0
Reputation: 3814
Button myButton = (Button)findViewById(R.id.BUTTON_ID);
EditText myEditText = (EditText)findViewById(R.id.EDITTEXT_ID);
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String myText = myEditText.getText().toString();
//do whatever with myText;
myEditText.setText("");
}
});
Where BUTTON_ID and EDITTEXT_ID are the id's assigned to each respectively in your XML file
Upvotes: 1