public class TestActivity extends Activity {
private Button NewSaying;
private TextView mInfoTextView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mInfoTextView = (TextView) findViewById(R.id.newsaying);
NewSaying = (Button)findViewById(R.id.one);
NewSaying.setOnClickListener(new ButtonclickListener());

}

private class ButtonclickListener implements OnClickListener {

public void onClick(View v) {
mInfoTextView.setText(R.string.saying1);
}
 }
}

On 12 April 2012 18:00, Jake Lin <cristiano850...@gmail.com> wrote:

> First, where is the "newsaying" TextView
> Then, you didn't add Button ClickListener
>
>
> On 11 April 2012 21:49, Clevin Dsouza <clevi...@gmail.com> wrote:
>
>> package com.example.rand;
>> import com.example.rand.R;
>> import android.app.Activity;
>> import android.os.Bundle;
>> import android.view.View;
>> import android.widget.Button;
>> import android.widget.TextView;
>>
>> public class NewSaying extends Activity
>> {
>>        private Button NewSaying;
>>
>>        public void onCreate(Bundle savedInstanceState) {
>>        super.onCreate(savedInstanceState);
>>        setContentView(R.layout.main);
>>
>>        TextView mInfoTextView = (TextView)
>> findViewById(R.id.newsaying);
>>
>>       }
>>
>>        private class ButtonclickListener implements View.onclickListener
>>        {
>>        int location;
>>
>>        public ButtonclickListener(int location)
>>        {
>>             this.location = location;
>>        }
>>
>>        public void onclick(View view)
>>        {
>>                TextView mInfoTextView = null;
>>                        mInfoTextView.setText(R.string.saying1);
>>
>>        }
>> }
>> }
>>
>>
>> No errors while compiling but when i run it i dont get the output. I
>> have written these codes to build an app that generates random strings
>> on the press of  a button.
>>
>> the string.xml
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <resources>
>>    <string name="hello">Hello World, AndroidRandomSayingsActivity!</
>> string>
>>    <string name="app_name">AndroidRandomSayings</string>
>>    <string name="saying1">A change is as good as a rest</string>
>>    <string name="saying2">A friend in need is a friend indeed</
>> string>
>>    <string name="saying3">A miss is as good as a mile</string>
>>    <string name="saying4">A penny saved is a penny earned</string>
>>    <string name="saying5">A word to the wise is enough</string>
>>    <string name="saying6">Actions speak louder than words</string>
>> </resources>
>>
>> main.xml
>> <?xml version="1.0" encoding="utf-8"?>
>> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
>> android"
>>    android:orientation="vertical"
>>    android:layout_width="fill_parent"
>>    android:layout_height="fill_parent"
>>    >
>>
>> <TextView android:text=" " android:layout_width="fill_parent"
>> android:layout_height="wrap_content"
>> android:layout_alignParentTop="true"
>> android:layout_alignParentLeft="true" android:layout_marginTop="55dp"
>> android:id="@+id/textView1"></TextView>
>>
>>  <TextView android:id="@+id/label"
>>              android:layout_width="fill_parent"
>>              android:layout_height="wrap_content"
>>              android:text="Click button to generate a random
>> saying!:" />
>>
>> <Button android:text="New saying "
>> android:layout_width="150px"
>> android:layout_height="70px"
>> android:textSize="15px"
>> android:textColor="#0066CC"
>> android:id="@+id/one"
>> android:layout_alignParentBottom="true"
>> android:layout_centerHorizontal="true"
>> android:layout_marginBottom="134dp"></Button>
>> <TextView android:text="a " android:textColor="#00EE00"
>> android:layout_width="fill_parent"
>> android:layout_height="wrap_content" android:id="@+id/label2"
>> android:layout_below="@+id/textView1"
>> android:layout_alignParentLeft="true"></TextView>
>>
>>
>> </RelativeLayout>
>>
>> --
>> 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
>
>
>
>
> --
> The quiter you become,the more you are able to hear.
>



-- 
The quiter you become,the more you are able to hear.

-- 
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