Thanks for the suggestions San and Fllip.  I have tried the example
that San gave but still errors.  Here's the revised code in the
main.xml file:

package com.HelloWorld;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Hello extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // start code here
        tv = (TextView) findViewById(R.id.TextView01);
        tv.setText("This is sample.");
        Button button = (Button) findViewById(R.id.Button01);
        button.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                Toast.makeText(Hello.this, "Hello World",
Toast.LENGTH_SHORT).show();
                                tv.setText("Button Clicked");
                        }
        });
    }
}


Errors are:

for the line: tv = (TextView) findViewById(R.id.TextView01);
--------  tv can not be resolved to a variable
for the line: tv.setText("This is sample.");  --------  tv can not be
resolved
for the line: tv.setText("Button Clicked");   --------  tv can not be
resolved

Any ideas why the errors?

On Aug 31, 4:56 pm, San <sanees...@gmail.com> wrote:
> As Havlicek said, create thetextviewusing findViewByID and set the
> text when button is clicked.
>
> Sample code:
>
> tv = (TextView) findViewById(R.id.TextView01);
> tv.setText("This is sample.");
> Button button = (Button) findViewById(R.id.Button01);
> button.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
>         tv.setText("Button Clicked");
>
> }
> });

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to