У меня есть listview, в котором есть TextView и флажок. ListView используется для заполнения данных из локальной базы данных SQLite. Если нажата кнопка, как можно получить идентификатор подэлемента ListView, чей флажок отмечен?CheckBox в ListView
Следующая моя main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/list_data"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_below="@+id/textViewTitle"
android:layout_marginTop="26dp"
android:layout_weight="1"
android:dividerHeight="0dip" >
</ListView>
<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Things To Remember"
android:textSize="25sp" />
</RelativeLayout>
Мой файл subitem.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Title:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignRight="@+id/check"
android:layout_marginLeft="44dp"
android:layout_marginRight="27dp"
android:layout_toRightOf="@+id/textView1"
android:paddingBottom="5dp"
android:text="Test Data"
android:textSize="15sp" />
<CheckBox android:id="@+id/check" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:layout_alignParentRight="true"
android:focusable="false"
></CheckBox>
</RelativeLayout>
Мой вопрос заключается в том, что, если я проверил флажков в каждом подпунктами и нажмите кнопку меню , как можно получить идентификаторы каждого выбранного подэлемента в avariable.
Спасибо за код. Но, когда я пишу вторую часть кода, он говорит, чтобы создать метод «getCheckedIds()». [IMG] http://i43.tinypic.com/9jhb3s.png [/ IMG] [IMG] http://i41.tinypic.com/232pds.png [/ IMG] –
Вы помещаете метод в другой метод? – buptcoder
Я вижу, что вы пишете метод в своем методе 'onCreate' ... – buptcoder