【发布时间】:2011-04-26 12:38:40
【问题描述】:
我是安卓开发的新手。我正在尝试创建一个具有微调器、编辑文本和复选框的列表。微调器和复选框的数据来自数据库。我有以下文件。
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
我根据数据库中的字段数获得多个微调器、复选框和编辑文本。我看到我们无法为复选框设置适配器,就像我为微调器设置的那样。
我只需要一个带有一个编辑文本和多个复选框(数据库行总数)的微调器。请帮忙!
【问题讨论】:
-
我还在等待回复。需要帮助!
标签: android listview checkbox android-edittext