Is this is OK to use the ListView for inline editi

2019-01-29 03:40发布

问题:

EDIT:

I can't write into the EditText, it disappears when i try to write something, its because the getView() is called when i modify the data

I need to load some data from SQLite & list it in a ListView or Grid. The next thing is to provide the inline editing functionality, i.e the user can edit the data also within that ListView OR grid.

Currently i am using the ListView for this purpose. What i have done is that i have defined layout for the row item, the sample xml is provide below:

rowitem.xml

   <TableRow
       android:id="@+id/tableRow1"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:weightSum="1">

       <TextView 
            android:text="" 
            android:id="@+id/txtQuestionId" 
            android:layout_width="100dp" 
            android:layout_height="50dp"
            android:clickable="true"
            android:padding="5dip"
            android:gravity="left"
            android:background="@android:color/transparent"/>        


       <EditText 
            android:text="" 
            android:id="@+id/txtQuestion" 
            android:layout_width="400dp" 
            android:layout_height="50dp"
            android:clickable="true"
            android:padding="3dip"
            android:gravity="left"
            />



        <TextView 
            android:text="" 
            android:id="@+id/txtStandard" 
            android:layout_width="200dp" 
            android:layout_height="50dp"
            android:padding="5dip"
            android:gravity="left"/>

        <RadioGroup android:id="@+id/rdbStatus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" android:weightSum="1">
            <RadioButton android:id="@+id/rbSAT" 
                        android:layout_width="wrap_content" android:text="SAT" 
                        android:layout_height="wrap_content"
                        android:onClick="onStatusClicked"/>
            <RadioButton android:id="@+id/rbUNSAT" 
                        android:layout_width="wrap_content" android:text="UNSAT" 
                        android:layout_height="wrap_content"
                        android:onClick="onStatusClicked"/>
            <RadioButton android:id="@+id/rbNA"     
                        android:layout_width="wrap_content" android:text="NA" 
                        android:layout_height="wrap_content"  
                        android:onClick="onStatusClicked"/> 
        </RadioGroup>       


  </TableRow>

        <!-- just draw a red line -->
    <View
        android:layout_height="2dip"
        android:background="#FF0000" />   

</TableLayout>

I am getting the data from SQLite & using a custom DataAdapter class bind the data with ListView.

I have few questions:

1- What are the best practices for inline editing in android?

2- What is the best option for inline Editiing ListView OR Grid?

3- What are pros & coins of using ListView for inline Editing?

Great Thanks.

回答1:

Ok, Its my personal opinion.. try if you like it..

  1. Fill data in your list from database. (No need of EditText in layout).

  2. Make a dialog with Edittext. Now when user click on ListItem open that dialog with pre-populated text from current selected list row textview. Then allow user to change in it. When user click OK on dialog then modify that Textview in list item..



回答2:

Why not? It would be definitely nice for user, but kind of tricky to develop.

  • Your list entry layout must provide text edit ( maybe invisible ) and switch to it on click on text view. This text view shall have suitale listener keeping track in parent layout etc.
  • you have to save data back as soon as textedit loses focus / about to being reclaimed by list view for reuse in cause fo scrolling.


回答3:

@yaqub use EditorActionListener with imeOptions="actionDone" like

  1. set the android:imeOptions="actionDone" property for edittext which is there in list.
  2. use editText.setOnEditorActionListener(onEditorActionListener)
  3. track if(actionId == EditorInfo.IME_ACTION_DONE) {//here do your action}