Reputation: 57
I'm new to android programming and not really good at java programming. Simple question here:How to store value typed in EditText to array once button is pressed, the way that I will able to compare each index to a constant value of another variable.
Upvotes: 1
Views: 6847
Reputation: 657
//your array
String[n] array;
//your button
Button b;
///your edittext
EditText e;
if(b.isPressed())
array[x]=edit.getText().toString();
OR using ArrayList
ArrayList<String> n= new ArrayList<String>();
//your button
Button b;
///your edittext
EditText e;
if(b.isPressed())
n.add(edit.getText().toString());
Upvotes: 2
Reputation: 31
Well this is quite easy. xml layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/txtField"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
So in your activity you type the following:
EditText text = (EditText) findViewById(R.id.txtField);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String s = text.getText().toString();
// then you do whatever you like with it
}
});
Upvotes: 0