title: setText Method from onClick Method in Android
body: <p>I am very new to Java and have encountered a problem. I have set up a TextView and want to call the <code>setText</code> method when a button is clicked from my dialog. This <code>TextView</code> is set up in my main activity. I have not initialized it as static as this produces an error. The line of code in question is - <code>Tabs.total.setText("PRINTING TO TEXT VIEW");</code> I want this to set the content of my <code>TextView</code> defined in my class Tabs.</p>
  
  <p>Variable <code>total</code> is defined like this - </p>
  
  <pre><code>TextView total = (TextView) findViewById(R.id.total_view);
  </code></pre>
  
  <p>I have looked a lot for some material on this problem but have failed to find a solution so far. I hope somebody can help. Thanks!!</p>
  
  <pre><code>public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      final View v;
      if(convertView==null){
          LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = li.inflate(R.layout.scrollergrid, null);
          final TextView tv = (TextView)v.findViewById(R.id.icon_text);
          tv.setTag(pos);
          tv.setText(mItems[pos]);
          TextView price = (TextView)v.findViewById(R.id.price_text);
          price.setText("$" + Prices[pos]);
  
          pos += 1;
          final ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
          iv.getLayoutParams().height = 150;
          iv.getLayoutParams().width = 150;
          iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
          iv.setImageResource(mThumbIds[position]);
          iv.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  id = tv.getTag();
                  System.out.println(mItems[(Integer) id] + " $" + Prices[(Integer) id]);
  
                  final Dialog dialog = new Dialog(mContext);
                  dialog.setContentView(R.layout.alertdialog);
                  dialog.setTitle(mItems[(Integer) id]);
  
                  ImageView dialogImage = (ImageView) dialog.findViewById(R.id.alert_image);
                  dialogImage.setImageResource(mThumbIds[(Integer) id]);
  
                  TextView itemDescription = (TextView) dialog.findViewById(R.id.item_description);
                  itemDescription.setText("A nice little piece of food. Good for all the family. Full of flavour!!");
  
                  TextView itemPrice = (TextView) dialog.findViewById(R.id.item_price);
                  itemPrice.setText("$" + Prices[(Integer) id]);
  
                  Button goBack = (Button) dialog.findViewById(R.id.go_back);
                  goBack.setOnClickListener(new OnClickListener() {
                  @Override
                      public void onClick(View v) {
                          dialog.cancel();
                      }
                  });
  
                  Button order = (Button) dialog.findViewById(R.id.order);
                  order.setOnClickListener(new OnClickListener() {
                  @Override
                      public void onClick(View v) {
                          Tabs.Order.add(mItems[(Integer) id] + " " + Prices[(Integer) id]);
                          System.out.println(Tabs.Order);
                          Tabs.total.setText("HIIII");
                          dialog.cancel();
                      }
                  });
  
                  dialog.show();
              } 
  
          });
  
      }
      else
      {
          v = convertView;
      }
      return v;
  }
  </code></pre>
  
  <p>}</p>