Editable list of items in application settings?

I am trying to do something similar to iOS editable UITableView in my application settings. This is basically a list where users can add items, delete them, or reorder. I am sure this is a common problem, but I have not found examples of how to do this.

Now I'm trying to do this by inserting two PreferenceScreens and moving elements between them:

enter image description here

I store elements on two different arrays ("added" elements and "not added" elements) and dynamically create both screens with addPreference(), however, I'm not sure if this is a good idea and how to allow users to delete and reorder the elements.

How can I do that?

+4
3

PreferenceScreen, . Activity, , ListView s. , visibility , visible gone , gone , - .

ArrayAdapter ( ArrayAdapter ListView s, ). , LinearLayout ImageView TextView , , :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/layoutImage"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_weight="2" 
        android:background="@drawable/..."/>

    <TextView
        android:id="@+id/layoutText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="8"
        android:layout_gravity="left"
        android:numLines="1"
        android:textSize="18sp" />
</LinearLayout>

ArrayAdapter - , R.id.your_new_layout, .

, onClickListener() getView() ( ArrayAdapter), ListView notifyDataSetChanged(), , , .

. ListView " ", , . , .sort() ArrayAdapter, , , 2 , ( ):

  • onDragEvent. this, ListView . , , , , List Adapter, .

  • . , , , , this, this .

, Activity, , , setVisibility() View.VISIBLE View.GONE ListView, , .

+1

.
, , .
.

0

DragSortListView, , Google Play .

This implementation is especially good, as it integrates easily and is extremely effective . It should fit your reordering / deletion needs.

0
source

Source: https://habr.com/ru/post/1530714/


All Articles