【问题标题】:custom Expendable List view child自定义可扩展列表视图子项
【发布时间】: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


    【解决方案1】:

    听起来好像您没有保存有关活动需要重新创建新状态的添加行的信息。使用本地数据存储或 savedInstanceState。

    【讨论】:

    • 如何将添加的视图保存在 savedInstanceState 中,能否提供示例代码,谢谢。谢谢
    • 您保存的不是您的视图,而是(新)视图显示的数据。它是一个模型-视图-控制器模式,不要忘记这一点! Google the savedInstanceState 的东西,但我自己直接写入数据库,因为 savedInstanceState 机制很奇怪......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多