title: How to set the value in text view getting from database in android?
body: <p>I am storing the values based on the position in Sqlite database</p>
  
  <p>I am retrieving the value from data base and the value is showing correct.But  when I display the value in text-view it becomes zero. </p>
  
  <p>Please help.</p>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>public class BabyWearAdapter extends BaseAdapter {
  
      ArrayList&lt;String&gt; p_id;
      ArrayList&lt;String&gt; p_name;
      Context context;
      ArrayList&lt;String&gt; imageId;
      ArrayList&lt;String&gt; wash_v;
      ArrayList&lt;String&gt; dry_v;
      ArrayList&lt;String&gt; iron_v;
      Typeface tf;
      ProgressDialog dialog;
  
      Intent i;
      float washItemCount = 0.0f;
      String iconName;
      Vector&lt;BasketDO&gt; vecBasket = new Vector&lt;BasketDO&gt;();
      int countVal1, countVal2, countVal3;
      public ImageLoader imageLoader;
      int KEY, pid;
      String TNAME;
      DBHandler dbHandler;
      SharedPreferences sharedPreferences;
      SharedPreferences.Editor editor;
  
      HashMap&lt;Integer, Integer&gt; launDry = new HashMap&lt;Integer, Integer&gt;();
      HashMap&lt;Integer, Integer&gt; stremIron = new HashMap&lt;Integer, Integer&gt;();
      HashMap&lt;Integer, Integer&gt; dryCleans = new HashMap&lt;Integer, Integer&gt;();
      public static ArrayList&lt;HashMap&lt;Integer, Integer&gt;&gt; mListLaundry = new ArrayList&lt;HashMap&lt;Integer, Integer&gt;&gt;();
  
      public BabyWearAdapter(Context con, ArrayList&lt;String&gt; pid,
              ArrayList&lt;String&gt; pname, ArrayList&lt;String&gt; pimg,
              ArrayList&lt;String&gt; wash, ArrayList&lt;String&gt; dry,
              ArrayList&lt;String&gt; iron) {
          p_id = pid;
          context = con;
          p_name = pname;
          imageId = pimg;
          wash_v = wash;
          dry_v = dry;
          iron_v = iron;
          imageLoader = new ImageLoader(context);
  
          sharedPreferences = context.getSharedPreferences("prefName",
                  context.MODE_APPEND);
          editor = sharedPreferences.edit();
  
      }
  
      @Override
      public int getCount() {
          return imageId.size();
      }
  
      @Override
      public Object getItem(int position) {
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
  
  
      @SuppressLint({ "UseValueOf", "ViewHolder" })
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = inflater.inflate(R.layout.dynamic, parent, false);
  
          final LinearLayout ll1 = (LinearLayout) convertView
                  .findViewById(R.id.ll1);
          final LinearLayout ll2 = (LinearLayout) convertView
                  .findViewById(R.id.ll2);
          final LinearLayout ll3 = (LinearLayout) convertView
                  .findViewById(R.id.ll3);
          final TextView tv1 = (TextView) convertView.findViewById(R.id.tv1);
          final TextView tv2 = (TextView) convertView.findViewById(R.id.tv3);
          final TextView tv3 = (TextView) convertView.findViewById(R.id.tv5);
          final ImageView img = (ImageView) convertView
                  .findViewById(R.id.ivImage);
  
          tv1.setText(wash_v.get(position));
          tv2.setText(iron_v.get(position));
          tv3.setText(dry_v.get(position));
          imageLoader.DisplayImage(imageId.get(position), img);
  
          dbHandler = new DBHandler(context);
  
          int pid = Integer.parseInt(p_id.get(position));
          SQLiteDatabase db = null;
          db = dbHandler.getReadableDatabase();
          i = new Intent("com.example.safewash");
          final  TextView tvVal = (TextView) convertView.findViewById(R.id.tvVal);
          final TextView  tvVal1 = (TextView) convertView
                  .findViewById(R.id.tvVal1);
          final  TextView tvVal2 = (TextView) convertView
                  .findViewById(R.id.tvVal2);
          ll1.setTag(p_id.get(position));
          ll2.setTag(p_id.get(position));
          ll3.setTag(p_id.get(position));
  
  
          Cursor c = db.rawQuery("select * from babywear_tbl where pid =" + pid,
                  null);
  
          if (c.moveToFirst()) {
  
  
                  String countVal1 = c.getString(c.getColumnIndex("laundry_item"));
                  String countVal2 = c.getString(c.getColumnIndex("dry_item"));
                  String countVal3 = c.getString(c.getColumnIndex("iron_item"));
  
                  final int count1 =Integer.parseInt(countVal1);
                  final int count2 =Integer.parseInt(countVal2);
                  final int count3 =Integer.parseInt(countVal3);
  
                  tvVal.setText("" + count1);
                  tvVal.setVisibility(View.VISIBLE);
  
  
  
  
  
                  System.out.println("The Value one is "+countVal1);
                  Log.i("Count Val One",""+countVal1);
  
          }
          try {
  
              int temp = launDry.get(Integer.parseInt(ll1.getTag().toString()
                      .trim()));
              int val = temp + 1;
              tvVal.setText("" + val);
              tvVal.setVisibility(View.VISIBLE);
  
          } catch (Exception e) {
              tvVal.setText("0");
          }
  
          try {
  
              int temp = stremIron.get(Integer.parseInt(ll2.getTag().toString()
                      .trim()));
              int val = temp + 1;
              tvVal1.setText("" + val);
              tvVal1.setVisibility(View.VISIBLE);
  
          } catch (Exception e) {
              tvVal1.setText("0");
          }
  
          try {
  
              int temp = dryCleans.get(Integer.parseInt(ll1.getTag().toString()
                      .trim()));
              int val = temp + 1;
              tvVal2.setText("" + val);
              tvVal2.setVisibility(View.VISIBLE);
  
          } catch (Exception e) {
              tvVal2.setText("0");
          }
  
          ll1.setOnClickListener(new OnClickListener() {
  
              @SuppressLint("NewApi")
              @Override
              public void onClick(final View v) {
                  int count = 0;
  
                  String washItem = wash_v.get(position);
                  int washItems = Integer.parseInt(washItem);
  
                  if (washItems != 0) {
                      int colorStart = Color.LTGRAY;
                      int colorEnd = 0;
  
                      ValueAnimator animator = ObjectAnimator.ofInt(v,
                              "backgroundColor", colorStart, colorEnd);
                      animator.setDuration(800);
                      animator.setEvaluator(new ArgbEvaluator());
                      animator.setRepeatCount(0);
                      animator.start();
  
                      washItemCount = Float.parseFloat(washItem);
  
                      tvVal.setVisibility(View.VISIBLE);
  
                      count = Integer.parseInt(tvVal.getText().toString());
                      countVal1 = ++count;
  
                      i.putExtra("washItemCount", washItemCount);
                      i.putExtra("countVal1", countVal1);
                      context.sendBroadcast(i);
                      try {
  
                          int temp = launDry.get(Integer.parseInt(ll1.getTag()
                                  .toString().trim()));
  
                          temp++;
                          launDry.put(Integer.parseInt(ll1.getTag().toString()
                                  .trim()), temp);
  
                          long id = dbHandler.insertBabyWearValues(Integer
                                  .parseInt(ll1.getTag().toString().trim()),
                                  countVal1, countVal2, countVal3);
  
                          if (id == -1) {
                              long updateid = dbHandler.updateBabyWear(countVal1,
                                      countVal2, countVal3);
                              Toast.makeText(context, "ID value" + updateid,
                                      Toast.LENGTH_SHORT).show();
  
                          }
                          Toast.makeText(context, "ID value" + id,
                                  Toast.LENGTH_SHORT).show();
  
                          Appconstants.laundryHashmap = launDry;
  
                          int val = temp + 1;
                          tvVal.setText("" + val);
                      } catch (Exception e) {
                          launDry.put(Integer.parseInt(ll1.getTag().toString()
                                  .trim()), 0);
                          tvVal.setText("" + 1);
                          e.printStackTrace();
                      }
  
                  }
              }
          });
  
          ll2.setOnClickListener(new OnClickListener() {
              @SuppressLint("NewApi")
              @Override
              public void onClick(final View v) {
                  int count = 0;
                  String washItem = iron_v.get(position);
  
                  washItemCount = Float.parseFloat(washItem);
                  int washItems = Integer.parseInt(washItem);
                  if (washItems != 0) {
                      int colorStart = Color.LTGRAY;
                      int colorEnd = 0;
                      ValueAnimator animator = ObjectAnimator.ofInt(v,
                              "backgroundColor", colorStart, colorEnd);
                      animator.setDuration(800);
                      animator.setEvaluator(new ArgbEvaluator());
                      animator.setRepeatCount(0);
                      animator.start();
                      washItemCount = Float.parseFloat(washItem);
  
                      tvVal1.setVisibility(View.VISIBLE);
                      count = Integer.parseInt(tvVal1.getText().toString());
                      countVal2 = ++count;
                      // tvVal1.setText("" + countVal2);
                      i.putExtra("washItemCount", washItemCount);
                      i.putExtra("countVal2", countVal2);
                      context.sendBroadcast(i);
  
                      try {
  
                          int temp = stremIron.get(Integer.parseInt(ll2.getTag()
                                  .toString().trim()));
                          temp++;
                          stremIron.put(Integer.parseInt(ll2.getTag().toString()
                                  .trim()), temp);
                          long id = dbHandler.insertBabyWearValues(Integer
                                  .parseInt(ll2.getTag().toString().trim()),
                                  countVal1, countVal2, countVal3);
                          Toast.makeText(context, "ID value" + id,
                                  Toast.LENGTH_SHORT).show();
                          if (id == -1) {
                              long updateid = dbHandler.updateBabyWear(countVal1,
                                      countVal2, countVal3);
                              Toast.makeText(context, "ID value" + updateid,
                                      Toast.LENGTH_SHORT).show();
  
                          }
                          Appconstants.ironHashmap = stremIron;
                          int val = temp + 1;
                          tvVal1.setText("" + val);
                      } catch (Exception e) {
                          stremIron.put(Integer.parseInt(ll2.getTag().toString()
                                  .trim()), 0);
                          tvVal1.setText("" + 1);
                          e.printStackTrace();
                      }
  
                  }
              }
          });
          ll3.setOnClickListener(new OnClickListener() {
  
              @SuppressLint("NewApi")
              @Override
              public void onClick(final View v) {
  
                  int count = 0;
                  String washItem = dry_v.get(position);
                  washItemCount = Float.parseFloat(washItem);
                  int washItems = Integer.parseInt(washItem);
                  if (washItems != 0) {
                      int colorStart = Color.LTGRAY;
                      int colorEnd = 0;
  
                      ValueAnimator animator = ObjectAnimator.ofInt(v,
                              "backgroundColor", colorStart, colorEnd);
                      animator.setDuration(800);
                      animator.setEvaluator(new ArgbEvaluator());
                      animator.setRepeatCount(0);
                      animator.start();
  
                      washItemCount = Float.parseFloat(washItem);
  
                      tvVal2.setVisibility(View.VISIBLE);
                      count = Integer.parseInt(tvVal2.getText().toString());
                      countVal3 = ++count;
                      // tvVal2.setText("" + countVal3);
                      i.putExtra("washItemCount", washItemCount);
                      i.putExtra("countVal3", countVal3);
                      context.sendBroadcast(i);
                      try {
  
                          int temp = dryCleans.get(Integer.parseInt(ll3.getTag()
                                  .toString().trim()));
                          temp++;
                          dryCleans.put(Integer.parseInt(ll3.getTag().toString()
                                  .trim()), temp);
                          long id = dbHandler.insertBabyWearValues(Integer
                                  .parseInt(ll3.getTag().toString().trim()),
                                  countVal1, countVal2, countVal3);
                          Toast.makeText(context, "ID value" + id,
                                  Toast.LENGTH_SHORT).show();
                          if (id == -1) {
                              long updateid = dbHandler.updateBabyWear(countVal1,
                                      countVal2, countVal3);
                              Toast.makeText(context, "ID value" + updateid,
                                      Toast.LENGTH_SHORT).show();
  
                          }
                          Appconstants.dryCleanHashmap = dryCleans;
                          int val = temp + 1;
                          tvVal2.setText("" + val);
                      } catch (Exception e) {
                          dryCleans.put(Integer.parseInt(ll3.getTag().toString()
                                  .trim()), 0);
                          tvVal2.setText("" + 1);
                          e.printStackTrace();
  
                      }
                  }
  
              }
          });
  
          return convertView;
      }
  
  }
  </code></pre>
  
  <p>Here the point is I wrote this logic adapter i.e getView().</p>