Hello everybody I have an edit text and button when I edited some value in edittext on clicking button done, the value need to store in a string array can any one help in fixing of this task ,Thanks in advance
3
-
2please copy your code so, that we can help youFasiha– Fasiha2015-03-31 07:54:01 +00:00Commented Mar 31, 2015 at 7:54
-
2Why should be this question upvoted?Giorgio Antonioli– Giorgio Antonioli2015-03-31 07:58:09 +00:00Commented Mar 31, 2015 at 7:58
-
1This will help you i feel android-mantra.blogspot.in/2013/09/…TechArcSri– TechArcSri2015-03-31 07:58:25 +00:00Commented Mar 31, 2015 at 7:58
Add a comment
|
3 Answers
Try Array List. use the following code in your main java
final ArrayList<String> list = new ArrayList<String>();
Button button= (Button) findViewById(R.id.buttonId);
final EditText editText = (EditText) findViewById(R.id.editTextId)
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
list.add(editText.getText().toString());
}
});
// to get i th element
int i=0;
Log.d("value", list.get(i));
Comments
Try:
...
int[] arr = new int[];
//listener
onclick()
{
arr = arr.addElement(arr,Integer.parseInt(et.getText().toString()));
}
}//oncreate end
static int[] addElement(int[] a, int e) {
a = Arrays.copyOf(a, a.length + 1);
a[a.length - 1] = e;
return a;
}
you should use List at place of string array, List is dynamic growing array so you can easily add and remove items from List as below:
List<String> list = new ArrayList<String>();
if(button clicked)
{
list.add(editText.getText().toString());
}
or if you are bound to use array of string in any case then follow "Kay" solution as well in that case you need to increment in item index in array before adding item into array.