Android Listview со спиннером и флажком
Я новичок в разработке Android. Я пытаюсь создать список, который имеет счетчик, текст редактирования и флажок. Данные для счетчика и флажок поступают из базы данных. У меня есть следующие файлы.
NewTransac class which extends ListActivity {
private PayDbAdapter mDbHelper;
private Spinner paySpinner;
private CheckBox mCheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_transac_listview);
mDbHelper = new PayDbAdapter(this);
mDbHelper.open();
populatedata();
}
private void populatedata() {
paySpinner = (Spinner)findViewById(R.id.payerspinner);
mCheckBox = (CheckBox)findViewById(R.id.paidforcheckboxname);
Cursor mCursor = mDbHelper.fetchAllTransactionValue();
startManagingCursor(mCursor);
// Create an array to specify the fields we want to display in the list.
String[] from = new String[]{PayDbAdapter.KEY_NAME};
int[] to = new int[]{android.R.id.text1};
int[] cbto = new int[]{R.id.paidforcheckboxname};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, mCursor, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
paySpinner.setAdapter(adapter);
SimpleCursorAdapter cbAdapter =
new SimpleCursorAdapter(this, R.layout.show_new_transac_data, mCursor, from, cbto );
setListAdapter(cbAdapter);
}
Представление списка xml
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:textSize="14sp"
/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_friends"
android:textSize="14sp"
/>
<Button android:id="@+id/confirmpay"
android:text="@string/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_vertical|center_horizontal|center">
</Button>
представление списка заполнено xml
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:text="@string/listSeparatorPay"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
/>
<Spinner android:id="@+id/payerspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/selectpayer"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/paytext"
/>
<EditText android:id="@+id/payamount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
/>
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:text="@string/listSeparatorPayedFor"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
/>
<CheckBox android:id="@+id/paidforcheckboxname"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText android:id="@+id/paidforamount"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
/>
Problem
Я получаю несколько блесен, чекбоксы и текст редактирования в зависимости от количества полей в базе данных. Я вижу, что мы не можем установить адаптер для флажка, как я установил для счетчика. Мне нужно получить только один счетчик с одним текстом редактирования и несколькими флажками (общее количество строк базы данных). пожалуйста помоги!