RadioButtonGroup are not showing up

after solving buttons succesfully by you guys now im having a problem that the radiobuttongroup aren't showing up

this is the code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android2="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="10" >

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp" 
        android:text="@string/Greetings" />

    <Button
        android:id="@+id/Button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="HelloWord" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:orientation="horizontal"
    android:weightSum="10"
    android2:baselineAligned="_baseline" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3.3"
        android:background="#ff0000"
        android:gravity="center"
        android:text="red"
        android:textColor="#000000" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="3.4"
        android:gravity="center"
        android:background="#00ff00"
        android:text="green"
        android:textColor="#000000"

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="3.3"
        android:gravity="center"
        android:background="#0000ff"
        android:text="blue"
        android:textColor="#000000" 

</LinearLayout>

<RadioGroup
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/myRadioGroup"
    android:orientation="horizontal">

<RadioButton
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weight="1"
    android:id="@+id/myRadioButtonRed" />

 <RadioButton
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weight="1"
    android:id="@+id/myRadioButtonGreen" />

  <RadioButton
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weight="1"
    android:id="@+id/myRadioButtonBlue" />

     </LinearLayout>
      </LinearLayout>

note: im having an error saying this TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="3.3" android:gravity="center" android:background="#0000ff" android:text="blue" android:textColor="#000000" must be followed by a attribute specification i hope i can get help and thanks


它应该是这样的

button1.setOnClickListener(new OnClickListener()
{
  public void onClick(View v)
  {
     //stuff
  }
});

button2.setOnClickListener(new OnClickListener()
{
  public void onClick(View v)
  {
     // stuff
  }
});

  • There's no Button.OnClickListener class. Use View.OnClickListener instead. Replace

    Button.OnClickListener myListener = new Button.OnClickListener()
    

    with

    View.OnClickListener myListener = new View.OnClickListener()
    
  • A class can have only one method with the same signature. Remove the other onClick(View) definition.


  • 只需使用这种方式

                @Override
                public void onCreate(Bundle savedInstanceState) 
                {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);
    
                    Button Button1=(Button)findViewById(R.id.Button1);
                    Button1.setOnClickListener(mClickListener);
                }
    
                View.OnClickListener mClickListener =new OnClickListener()
                {           
                    @Override
                    public void onClick(View v) {
                    // write your code here
    
                    }
                };
    
    链接地址: http://www.djcxy.com/p/24262.html

    上一篇: 使用Eclipse GWT 2.0插件更新jar时出错

    下一篇: RadioButtonGroup没有显示出来