title: Buttons and TextView in Android
body: <p>I'm trying to learn the ins and outs of <code>Android</code> and I'm finding some real challenges. I am trying to link a <code>Button</code> to a <code>TextView</code>, when you click the <code>Button</code> the value in the <code>TextView</code> changes. I've tried to use some of the sample code I've found online but I get a lot of errors and I'm not sure what to do with them. I'd appreciate any help you could offer.</p>
  
  <p>Thanks so much for your help!</p>
  
  <p>at line 25:</p>
  
  <pre><code>Multiple markers at this line
  - main cannot be resolved or is not a field
  - R cannot be resolved to a variable
  </code></pre>
  
  <p>at line 29:</p>
  
  <pre><code>btn1 cannot be resolved or is not a field
  </code></pre>
  
  <p>at line 32:</p>
  
  <pre><code>Syntax error on token(s), misplaced construct(s)
  </code></pre>
  
  <p>at line 34:</p>
  
  <pre><code>Multiple markers at this line
  - Syntax error on token ")", ; expected
  - Syntax error on token "(", ; expected
  - void is an invalid type for the variable onClick
  </code></pre>
  
  <p>at line 36:</p>
  
  <pre><code>txtVw1 cannot be resolved or is not a field
  </code></pre>
  
  <p>and then here is my code:</p>
  
  <pre><code>package com.demuro1.views;
  import android.R;
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_list_item);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  Button aBut = (Button) findViewById(R.id.btn1);
  
  public void changeText(){
      mButton.setOnClickListener(new View.OnClickListener {
          public void onClick(View v) {
              final TextView mTextView = (TextView) findViewById(R.id.txtVw1);
              mTextView.setText("Some Text");
          }
      };
  }
  
  }
  </code></pre>
  
  <p>and then the <code>xml</code> from the view</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="horizontal" &gt;
  
              &lt;LinearLayout
                  android:layout_width="129dp"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:orientation="vertical" &gt;
  
                  &lt;TextView
                      android:id="@+id/txtVw1"
                      android:textSize="25sp"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="press button 1" /&gt;
  
                  &lt;Button
                      android:id="@+id/btn1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_vertical"
                      android:text="Button 1" 
                      android:onClick="activateBtn1"/&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="140dp"
                  android:layout_height="fill_parent"
                  android:layout_gravity="center_vertical"
                  android:orientation="vertical" &gt;
  
                  &lt;TextView
                      android:id="@+id/txtVw2"
                      android:textSize="25sp"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="press button 2" /&gt;
  
                  &lt;Button
                      android:id="@+id/btn2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Button 2" 
                      android:onClick="activateBtn2"/&gt;
                      /&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>