Erstelle eine ListView mit wählbaren Zeilen / ändere die Hintergrundfarbe der ListView-Zeilen, wenn du auf @ klick

Proble

Ich versuche ein @ zu erstellListView mit auswählbaren Elementen. Ich möchte in der Lage sein, auf ein Element im @ zu klickListView und lassen Sie das Element die Farbe in der Liste ändern. Fahren Sie dann fort und führen Sie einen anderen Vorgang mit den Daten aus der Zeile aus.

Ich benutze einSimpleAdapter.

Wie stelle ich das so ein, dass beim Tippen auf eine Zeile eine andere Farbe angezeigt wird. Wenn ich dann auf eine andere Zeile tippe, wird die neue Zeile ausgewählt und in eine neue Farbe geändert, und die alte Zeile wird wieder in geändert normal

Cod

Hier ist mein Code soweit. DasDBTools class is enthält alle Daten, die in meinem @ angezeigt werden solleListView organisiert und betreut. DasgetAllReceivers() Methode gibt ein @ zurüArrayList vonHashMap<String, String>s, die alle meine Daten haben.

MainActivity.java:

public class MainActivity extends ListActivity {
    DBTools dbTools = new DBTools(this);

    ArrayList<HashMap<String, String>> receiverList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().hide();
        setContentView(R.layout.activity_main);

        receiverList = dbTools.getAllReceivers();
        dbTools.close();
        ListView listView = getListView();
        if(receiverList.size() != 0) {

            SimpleAdapter adapter = new SimpleAdapter(MainActivity.this,receiverList, R.layout.receiver_entry, new String[] {"receiverId","receiverName", "fullPath"}, new int[] {R.id.receiverId, R.id.receiverName, R.id.fullPath});
            setListAdapter(adapter);
        }
    }
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/black" >

        <TextView
            android:id="@+id/titleTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="My List" />

    </TableRow>

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/black"
            android:id="@android:id/list" />

</TableLayout>

receiver_entry.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tableRow" >

    <TextView
        android:id="@+id/receiverId"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" />

    <TextView
        android:id="@+id/receiverName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Robotronics" />

    <TextView
        android:id="@+id/fullPath"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="123.45.678.910:8088/robtrox/find" />


</TableRow>

Antworten auf die Frage(1)

Ihre Antwort auf die Frage