Not considering that this is a good user interface design, here's how you do it:
public class TestList { public void blah() { ArrayAdapter<DataBucket> listAdapter = new ArrayAdapter<DataBucket>() { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.testlayout, null); } final DataBucket dataBucket = getItem(position); final EditText editText = (EditText) convertView.findViewById(R.id.theText); editText.setText(dataBucket.getSomeData()); editText.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } public void afterTextChanged(Editable editable) { dataBucket.setSomeData(editable.toString()); } }); return convertView; } }; } public static class DataBucket { private String someData; public String getSomeData() { return someData; } public void setSomeData(String someData) { this.someData = someData; } } }
'DataBucket' is a placeholder. You need to use any class that you created to store the data that is placed and edited in the editing text. TextWatcher will reference the data object that is being referenced. When scrolling, edit text fields should be updated with current data, and text changes should be saved. You can track which objects have been modified by the user to increase the efficiency of data / network updates.
* Change *
To use an int position instead of a direct reference to an object:
ArrayAdapter<DataBucket> listAdapter = new ArrayAdapter<DataBucket>() { @Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.testlayout, null); } final DataBucket dataBucket = getItem(position); final EditText editText = (EditText) convertView.findViewById(R.id.theText); editText.setText(dataBucket.getSomeData()); editText.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } public void afterTextChanged(Editable editable) { getItem(position).setSomeData(editable.toString()); } }); return convertView; } };
* Change again *
I feel compelled to say for posterity that in fact I would not call it that. I suppose you want more structured data than a String array, and you support the String array outside, just like an ArrayAdapter, so this is kind of a weird parallel situation. However, this will work fine.
I have my data in one String array, and not in a multidimensional array. The reason is that the data model that supports the GridView is a simple list. It may not be logical, but it is. GridView should do the layout itself, and if it is left on its own devices, it will fill the string with variable numbers of cells, depending on how much data you have and how wide your screen is displayed (AFAIK).
Enough chat. The code:
public class TestList extends Activity { private String[] guess;