Android 从FragmentActivity中的ExpandableListView获取子视图,而不包含childClick事件
我有几节课。第一类扩展自FragmentActivity,第二类是适配器扩展自BaseExpandableListAdapter。还有模型课 头等舱: 按类型列出每个子级的XML视图,可能的类型为EditText、TextView、Switch、单选弹出列表。 并在适配器getChildView中按类型(editText、TextView等)分配完整视图,例如:Android 从FragmentActivity中的ExpandableListView获取子视图,而不包含childClick事件,android,listview,expandablelistview,android-fragmentactivity,expandablelistadapter,Android,Listview,Expandablelistview,Android Fragmentactivity,Expandablelistadapter,我有几节课。第一类扩展自FragmentActivity,第二类是适配器扩展自BaseExpandableListAdapter。还有模型课 头等舱: 按类型列出每个子级的XML视图,可能的类型为EditText、TextView、Switch、单选弹出列表。 并在适配器getChildView中按类型(editText、TextView等)分配完整视图,例如: child.setView(holder.editText); 最后在碎片活动中使用 private void checkParam
child.setView(holder.editText);
最后在碎片活动中使用
private void checkParameters() {
boolean validated = true;
int groupCount = expandList.getExpandableListAdapter().getGroupCount();
for (int i = 0; i < groupCount; i++) {
int childCount = expandList.getExpandableListAdapter().getChildrenCount(i);
for (int j = 0; j < childCount; j++) {
Child child = (Child) expandList.getExpandableListAdapter().getChild(i, j);
//secure check
if (child.getView() != null) {
int itemType = child.getType();
//only editText
if (itemType >= 1 && itemType <= 7) {
EditText ed = (EditText) child.getView();
//do something
}
}
}
}
}
private void checkParameters(){
布尔值=真;
int groupCount=expandList.getExpandableListAdapter().getGroupCount();
对于(int i=0;i 如果(ItMyType=1 & & ItMyMyIHO,在任何代码中都有一些小部件,如代码> EddieTeX <代码>是一个糟糕的设计。如果有人拿枪指着我的头,强迫我去做,我会考虑让他们扣动扳机。也就是说,如果我在某种程度上确信写了这样的东西,我会在小部件上使用侦听器。(例如,EditText
上的TextWatcher
)并更新我的模型对象(或这些模型对象的副本,如果需要先进行验证)顺便说一句,我忘了提到实时基于用户输入,但我唯一的例子是在您正在寻找的领域,它将RatingBar
小部件放在每一行中。正如您将在示例中看到的,当用户点击RatingBar
小部件时,我连接侦听器来更新模型数据。这样,行记录循环有效——我们不希望仅仅因为用户滚动列表就失去用户的评级。更详细的示例将把更改的评级保存在持久的位置(例如数据库)。谢谢。目前,我在EditText-afterTextChanged.child.setValue(holder.EditText.getText().toString()的侦听器中更新数据模型);我在想可能有更有效的方法。。。
/**
* Model of each parameters
*/
public class Child {
private String name;
private String value;
private int type;
private int paramId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getParamId() {
return paramId;
}
public void setParamId(int paramId) {
this.paramId = paramId;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:id="@+id/txt_task_detail_info_param"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:minWidth="150dp"
android:focusable="false"
android:clickable="false"
android:padding="20dp"
android:textSize="14sp"
android:layout_toLeftOf="@+id/txt_task_detail_info_param_input"
android:layout_alignParentLeft="true" />
<EditText
android:id="@+id/txt_task_detail_info_param_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="150dp"
android:maxWidth="200dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="14sp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
|------------------Save button--|
| <ExpandableList> | |
| group1 | |
| child1: textView EditText | |
| child2: textView Switch | |
| group2 | |
| child1: textView TextView | |
|-------------------------------|
private View view;
child.setView(holder.editText);
private void checkParameters() {
boolean validated = true;
int groupCount = expandList.getExpandableListAdapter().getGroupCount();
for (int i = 0; i < groupCount; i++) {
int childCount = expandList.getExpandableListAdapter().getChildrenCount(i);
for (int j = 0; j < childCount; j++) {
Child child = (Child) expandList.getExpandableListAdapter().getChild(i, j);
//secure check
if (child.getView() != null) {
int itemType = child.getType();
//only editText
if (itemType >= 1 && itemType <= 7) {
EditText ed = (EditText) child.getView();
//do something
}
}
}
}
}