我使用ExpandableListActivity
與ExpandListAdapter
組合。ExpandableListView每行有2個項目,獲取子值
我的佈局:
---------------------------------
| <TextView> |
| |
|-------------------------------|
| <ExpandableList> | |
| group1 | |
| child1: textView editText | |
| child2: textView switch | |
| group2 | |
| child1: textView textView | |
|-------------------------------|
| <footerView> |
| [button] |
---------------------------------
這裏是我的child_layout(去除不必要的部分):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvChild"
android:layout_width="400px"
android:layout_height="wrap_content"
android:focusable="false" />
<EditText
android:id="@+id/etChild"
android:layout_width="400px"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/tvChild2"
android:layout_width="600px"
android:layout_height="wrap_content"
android:visibility="gone" />
<Switch
android:id="@+id/switchChild"
android:layout_width="400px"
android:layout_height="wrap_content"
android:textOff="NO"
android:textOn="YES"
android:visibility="gone" />
</LinearLayout>
這是我怎麼添加按鈕,開關或TextView的每個孩子:
Switch swc = (Switch) view.findViewById(R.id.switchChild);
EditText etc = (EditText) view.findViewById(R.id.etChild);
TextView tvc = (TextView) view.findViewById(R.id.tvChild2);
if (groupPosition == 0) {
swc.setVisibility(View.GONE);
tvc.setVisibility(View.GONE);
etc.setVisibility(View.GONE);
if (childPosition == 0)
etc.setVisibility(View.VISIBLE);
if (childPosition == 1)
etc.setVisibility(View.VISIBLE);
if (childPosition == 2) {
tvc.setVisibility(View.VISIBLE);
tvc.setText(GlobalVariables.currentSelectedCar);
}
}
因此,每個孩子都有一個TextView
whi ch不會改變,加上用戶可編輯的EditText/TextView/Switch
之一。當我點擊底部的按鈕時,我想要獲得每個孩子的可編輯項目值。
有U實現了這個事情嗎?我正在尋找相同的,但得到問題,從兒童視角檢索數據 – 2013-06-13 05:42:23
如果您仍然有問題,請聯繫我 – wervdon 2014-06-17 10:31:16