【发布时间】:2012-04-06 00:20:06
【问题描述】:
我有一个问题,我有一个消耗性列表视图,子行是一个自定义行,其中包含 textViews 和 Button 以及一个 LinearLayout,当我单击子视图中的按钮时,我想以编程方式添加一个 EditText 视图。 .
我在这部分没有问题,我可以在单击按钮时添加视图,但我的问题是当我从操作栏选项卡移动到另一个活动时,我添加的 EditText 视图消失了,我看不到即使我在上面写了一遍,我也需要一直可见
谁能告诉我这是什么问题以及尽快解决它的任何方法..请
谢谢你,
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final View rowview =super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final EditText item_count=(EditText)rowview.findViewById(R.id.txt_count);
Cursor child=getChild(groupPosition,childPosition);
item_count.setText(String.valueOf(child.getInt(child.getColumnIndex("quantity"))));
// EditText comment=(EditText)rowview.findViewById(R.id.iman);
// comment.setText("Add your comment here ");
ImageButton btn_add_count=(ImageButton)rowview.findViewById(R.id.btn_add_item);
btn_add_count.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
count=Integer.valueOf(item_count.getText().toString());
count=count+1;
item_count.setText(String.valueOf( count));
}
});
//this is the button which i click to add the views
Button btn_add_comment=(Button)rowview.findViewById(R.id.btb_add_comment);
btn_add_comment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LayoutInflater inflater=LayoutInflater.from(getActivity());
commentLayout=(LinearLayout)rowview.findViewById(R.id.comment_layout);
final LinearLayout rowLayout=new LinearLayout(getActivity());
//
Button remove=new Button(getActivity());
remove.setText("remove");
remove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// int index=rowLayout.getId();
commentLayout.removeView(rowLayout);
//rowLayout.setVisibility(View.GONE);
Log.i("remove", "this is remove comment");
}
});
rowLayout.setOrientation(LinearLayout.HORIZONTAL);
EditText comment_text=new EditText(getActivity());
comment_text.setBackgroundColor(Color.WHITE);
comment_text.setTextColor(Color.BLACK);
comment_text.setWidth(400);
comment_text.setHeight(40);
rowLayout.addView(remove);
rowLayout.addView(comment_text);
commentLayout.addView(rowLayout);
}
});
return rowview;
}
【问题讨论】:
标签: android layout expandablelistview