2012-03-21 5 views
0

У меня проблема, у меня есть список расходуемых списков, а дочерняя строка - это настраиваемая строка, содержащая textViews и Button и LinearLayout, которые я хочу добавить в программу EditText программно, когда я нажимаю на кнопку в представлении ребенка.custom Expendable List view child

У меня нет проблем в этой части, я могу добавить представление, когда я нажимаю на кнопку, но моя проблема в том, что когда я перехожу к другому действию на вкладках в панели действий, те виды 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; 
      }  

ответ

0

Это звучит так, как будто вы не сохраните информацию о добавленных строках, что активность необходимо воссоздать новое состояние. Используйте либо хранилище данных homegrown, либо savedInstanceState.

+0

Как я могу сохранить добавленный вид в savedInstanceState, не могли бы вы предоставить мне пример кода, пожалуйста. Спасибо – Basant

+0

, вы не сохраняете свои представления, а данные, отображаемые (новые). Его модель-вид-контроллер шаблон, не забывайте об этом! Google - материал savedInstanceState, но я сам пишу прямо в базу данных, так как механизм savedInstanceState странный ... – Bondax