title: Saving text and checkbox state in custom list
body: <p>I am making a custom list and I want to save the text of some TextFile which is in R.id.quantity.</p>
  
  <p>I also want to save the state of a checkbox. I tried to manage checked state of a checkbox in a list.</p>
  
  <p>The List contains other view controls. I have put them in a Viewholder class. I am initializing qtyTxtV with some initial array value, once an event occurs in this code the value of the array changes but the list contents gets erased. Please help out. </p>
  
  <p>Now this code is giving me a null pointer exception:</p>
  
  <pre><code>class MyAdapter1 extends BaseAdapter {
  Context context;
  ArrayList&lt;Integer&gt; price = new ArrayList&lt;Integer&gt;();
  ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();
  public static HashMap&lt;Integer, String&gt; myList = new HashMap&lt;Integer, String&gt;();
  static class ViewHolder {
      public TextView tvQuantityName, tvPrice, tvDishName;
      public ImageView imv1, imv2, imv3, imv4, imv5;
      public EditText edtQty;
      public CheckBox chkAdd;
  }
  public MyAdapter1(VegDetail vegDetail, ArrayList&lt;String&gt; names2,
          ArrayList&lt;Integer&gt; price2) {
      this.context = vegDetail;
      this.names = names2;
      this.price = price2;
      }
  @Override
  public int getCount() {
      return names.size();
  }
  
  @Override
  public Object getItem(int position) {
      return null;
  }
  @Override
  public long getItemId(int position) {
      return 0;
  }
  @SuppressWarnings("null")
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
  
      View row = convertView;
      ViewHolder holder = null;
  
      // View row = inflater.inflate(R.layout.rowlayout, parent, false);
      if (row == null) {
          LayoutInflater inflater = LayoutInflater.from(context);
              row = inflater.inflate(R.layout.rowlayout, parent, false);
          holder.edtQty = (EditText) row.findViewById(R.id.quantity);
          holder.imv1 = (ImageView) row.findViewById(R.id.star1);
          holder.imv2 = (ImageView) row.findViewById(R.id.star2);
          holder.imv3 = (ImageView) row.findViewById(R.id.star3);
          holder.imv4 = (ImageView) row.findViewById(R.id.star4);
          holder.imv5 = (ImageView) row.findViewById(R.id.star5);
          holder.tvDishName = (TextView) row.findViewById(R.id.item_name);
          holder.tvPrice = (TextView) row.findViewById(R.id.price1);
          holder.tvQuantityName = (TextView) row.findViewById(R.id.qtyTxtV);
          holder.chkAdd = (CheckBox) row.findViewById(R.id.chkAdd);
          EditText edtQty = (EditText) row.findViewById(R.id.quantity);
          edtQty.setText(VegDetail.qtyArray[position].toString());
          CheckBox chkAdd = (CheckBox) row.findViewById(R.id.chkAdd);
          chkAdd.setSelected(VegDetail.chkArray[position]);           
          holder.edtQty.addTextChangedListener(new TextWatcher() {
              public void onTextChanged(final CharSequence s,
                      final int start, final int before, final int count) {
              }
              public void afterTextChanged(final Editable s) {
                  int newValue;
                  final String boxContents = s.toString();
                  if (!boxContents.isEmpty()) {
                      try {
                          newValue = Integer.parseInt(boxContents);
                          VegDetail.qtyArray[position] = newValue;
                      } catch (final Exception exc) {
                          VegDetail.qtyArray[position] = 0;
                      } finally {
                      }
                  } else {
                      VegDetail.qtyArray[position] = 0;
                  }
              }
              public void beforeTextChanged(final CharSequence s,
                      final int start, final int count, final int after) {
              }
          });
  
          row.setTag(holder);
      } else {
          holder = (ViewHolder) row.getTag();
      }
  
      CheckBox chkAdd=(CheckBox)row.findViewById(R.id.chkAdd);
      chkAdd.setOnCheckedChangeListener(new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView,
                  boolean isChecked) {
              //VegDetail is another class where I gonna use checked list's states
              VegDetail.chkArray[position] = isChecked;               
          }
      });
      final TextView tv1 = (TextView) row.findViewById(R.id.item_name);
      TextView tv2 = (TextView) row.findViewById(R.id.price1);
      final TextView tvQty = (TextView) row.findViewById(R.id.quantity);
      tv1.setText(names.get(position));
      tv1.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(context,
                      "itme name is=&gt;" + tv1.getText().toString(),
                      Toast.LENGTH_LONG).show();
          }
      });
      tv2.setText("Rs:" + price.get(position));   
      return row;
  }
  }
  </code></pre>