奇怪的行为在Expandablelistview-安卓
-
30-09-2019 - |
题
我试图执行一个活动使用的ExpandableListView和我已经得到了这么远,但现在我已经找到一些奇怪的行为。
我的活动是为了记录的食物摄入量为指定的用户。他们有一个选择的菜单(早餐、午餐和晚餐-外集团)扩大,以显示它们的内容。当一个用户点击在内的菜单项的对话中出现,要求他们的数量一旦他们输入一个数量和关闭对话的文字上的菜单项的改变,以反映数量的项目,已经消耗
上图显示了该名单在一个封闭状态。
下面的列表之后我有打开的午餐菜单点击'薯片'和指示的数量为1。正如你可以看到的'土豆'itemtext现在已经改变,以反映数量为1。
奇怪的一部分发生在现在。如果我点击'午餐'和关闭清单然后点击它再次重新打开它,'数量的X1'的文本已上升到另一个项目(牛奶)
每次我打开并且关闭它列跳之间来回两个项目。此外,如果我打开了其他项目,例如早餐,我发现,他们也已经得到的项目与'数量的X1'虽然我还没有击他们。
该位代码都是相关的,是这样的:
XML的孩子元件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/childname"
android:paddingLeft="50dip"
android:textSize="14dip"
android:textStyle="italic"
android:layout_width="200dip"
android:textColor="@color/black"
android:layout_height="40dip"/>
<TextView android:id="@+id/qty_display"
android:text="-"
android:textSize="14dip"
android:textStyle="italic"
android:layout_width="50dip"
android:textColor="@color/black"
android:layout_height="wrap_content"/>
</LinearLayout>
代码这就是触发点击一个孩子元件:
public boolean onChildClick(
ExpandableListView parent,
View v,
int groupPosition,
int childPosition,
long id) {
// open the dialog and inflate the buttons
myDialog = new Dialog(this);
myDialog.setTitle("Food Item Qty");
myDialog.setContentView(R.layout.food_intake_dialog);
final Button ok = (Button)myDialog.findViewById(R.id.fi_ok_but);
Button cancel = (Button)myDialog.findViewById(R.id.fi_cancel_but);
//the id for this item is stored as a hash key in a map (say, item_id01)
String key = "item_id"+groupPosition+""+childPosition;
current_selected_food_item_id = Integer.parseInt(itemMap.get(key));
// inflate the textview that shows the qty for this item on the expandablelist
barQty = (TextView) v.findViewById(R.id.qty_display);
// set the ok button to record teh quantity on press
ok.setOnClickListener(new OnClickListener() {
public void onClick(View viewParam) {
//inflate the input box that receives quantity from user
EditText fiQty = (EditText) myDialog.findViewById(R.id.fiQty);
// get the quantity and append the text on hte list item
String qty = fiQty.getText().toString();
barQty.setText("Qty X "+qty);
//open the database and save state
FoodIntake.this.application.getFoodIntakeHelper().open();
FoodIntake.this.application.getFoodIntakeHelper().storeFoodIntakeLog(current_selected_food_item_id,qty,visit_id,remote_visit_id);
String log = FoodIntake.this.application.getFoodIntakeHelper().getFoodIntakeLog(visit_id);
FoodIntake.this.application.getFoodIntakeHelper().close();
// append the main food intake list and close the dialog
list.setText("Food Intake Log:\n\n"+log);
myDialog.cancel();
}
});
上述代码打开了对话,接受有价值的数量、附加单元,以反映这一点,还可以节省的数据库,并设置一个控与所选择的项目和数量。
抱歉刚刚把整个载荷的代码,但这已经让我难倒希望有人可以提供帮助。
感谢
凯文
解决方案
我不认为该问题是与对话。我有同样的问题在我的项目并不能解决它。我认为的 ExpandableListView
有一个错误的时候开幕的儿童。我只有一个孩子,每个组和的时候我展开一个小组,将儿童转移到另一团体。在检验之后,我发现,当我展开的儿童重新加载。
其他提示
安卓重新使用的对话。这样的行为你看到的可能的结果。你可以使用的一个活动管理的对话和使用 onPrepareDialog() 更新对话的内容。