开发者

Android listview and saving contents [duplicate]

This question already has answers here: Dynamic length of Listview of Edittext not saving input 开发者_开发技巧 (2 answers) Closed 2 years ago.

I have a ListActivity with the following adapter

this.setListAdapter(new JobTaskItemAdapter(this, jobTaskItems));

jobTaskItems is a List and can vary in size from 10 to 100 objects. The adapter returns a new compound view for each JobTaskItem:-

[TextView][EditText][TextView]

The user will go through the list and edit the applicable EditText boxes and then select a Save option. I then need to iterate through every view in the list, retrieve the edited text and save it in a JobTaskItem string field which will then be saved to SQLite db. However I cannot see how to access the data from views that have been scrolled off the screen?

Thanks


When ListView item disappears from the screen is can be destroyed/reused. You cannot rely on it then. You should save those data before list is scrolled.


It really has nothing to do with views that have been scrolled off the screen... I think there are a couple issues here, firstly, you should use a scrollView in your xml layout so you can access said fields, and second, Im assuming you are dynamically adding these compund [TextView][EditText][TextView]'s to your layout based on the size of jobTaskItems. What I would be in this case, is in your loop that dynamically adds these views, set references to your Textviews / EditTexts via an array:

TextView []TextViewArray1 = new TextView[jobTaskItems.length];
TextView []TextViewArray2 = new TextView[jobTaskItems.length];
EditText []EditTextArray = new EditText[jobTaskItems.length];

int i = 0; //used as array indexer
for (your_dynamically_added_views) {
  YOUR_CODE;
  TextViewArray1[i] = Dynamic_TextView_1;
  TextViewArray2[i] = Dynamic_TextView_2;
  EditTextArray[i] = Dynamic_EditText;
}

Then you can access these values later for manipulation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜