Is this is OK to use the ListView for inline editi

2019-01-29 03:09发布

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.

3条回答
干净又极端
2楼-- · 2019-01-29 03:34

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楼-- · 2019-01-29 03:43

@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}
查看更多
Anthone
4楼-- · 2019-01-29 03:56

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..

查看更多
登录 后发表回答