I m having a strange behaviour there. Probably something stupid but can't find out the solution
I m developing an application that displays a table (like an excel stuff) so that each row allows a user to enter values for several characteristics of an item (same characteristics for each item).
开发者_StackOverflowI have written an xml file for the row and, within a ListView, I inflate the file for each item. The row is basically made of several EditText and TextView.
Everything seems to work fine but when I enter data, as soon as the virtual keyboard disappears, every data I have typed before also disappear. It seems to be a problem when inflating since when I am directly using setContentView with the XML file of my row, there is no such problem.
Any idea?
Following is the code where my XML file is inflated (it is called from the getView method of an ArrayAdapter for a ListView):
private View generateItemRowView(int position, ViewGroup parent){
String itemName = itemList[position];
LayoutInflater inflater=this.getLayoutInflater();
View result =inflater.inflate(R.layout.item_row_layout, parent, false);
Button rowName=(Button)result.findViewById(R.id.row_item_name);
rowName.setTag(""+position);
rowName.setText(itemName);
return result;
}
Thanks
Try to change the second row with this:
LayoutInflater inflater = (LayoutInflater) this.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
This works in my projects^^
afaik ListView recycles views (uses several for all data). Any data changes (as they occur or at the input end) must be stored somewhere. When required (getView call) the data (changed) must be set too. Search for "notorious" fancy list by Mark Murphy.
Ok found more or less the origin of the problem and changed my strategy to resolve it.
It seems ListView
doesn't like EditText
in its rows when inflated (at least in what I did. So I created a LinearLayout
full of all the rows that I had previously in my ListView
, and inserted the resulting LinearLayout
into a ScrollView
. Now everything is working well. Still I can't find out why it was not working the initial way I did it.
精彩评论