2013-12-19 59 views
1

成功地解決按鈕由你們現在即時通訊有問題後,該RadioButtonGroup中沒有顯示出來RadioButtonGroup中沒有顯示出來

這是代碼

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

注:有一個錯誤說IM此的TextView 機器人:layout_width = 「FILL_PARENT」 機器人:layout_height = 「FILL_PARENT」 機器人:layout_weight = 「3.3」 機器人:比重= 「中心」 機器人:背景= 「#0000FF」 的android:文本=「藍色」 機器人:文字顏色=「#000000」必須跟一個屬性規範 我希望我能得到幫助,並感謝

回答

1

應該是這樣的

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

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

不工作仍然 –

+0

發佈完整代碼.. –

0

只是用這種方式

  @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 

       } 
      }; 
1
  1. 有沒有Button.OnClickListener類。改爲使用View.OnClickListener。更換

    Button.OnClickListener myListener = new Button.OnClickListener() 
    

    View.OnClickListener myListener = new View.OnClickListener() 
    
  2. 一個類只能有一個具有相同簽名的方法。刪除其他onClick(View)的定義。

+0

仍然是我的問題是最後一句 –

0

應該實行按鈕(Onclicklistener)這樣的..檢查下面的代碼

Button btn; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    btn = (Button) findViewById(R.id.button1); 

    btn.setOnClickListener(listener); 

} 

View.OnClickListener listener = new View.OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     if (v == btn) { 
      Toast.makeText(MainActivity.this, "test", Toast.LENGTH_LONG) 
        .show(); 
     } 
    } 
}; 
+0

這給出了更多的錯誤 –

0

ü也可以用這樣的方式......

Button Button1=(Button)findViewById(R.id.Button1); 
Button Button2=(Button)findViewById(R.id.Button2); 
    View.OnClickListener myListener = new View.OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
     if(view.getId()==R.id.Button1){ 
      Toast.makeText(Nasser.this, "Button1", Toast.LENGTH_LONG).show(); 
     } 
     else if(view.getId()==R.id.Button2){ 
      Toast.makeText(Nasser.this, "Button2", Toast.LENGTH_LONG).show(); 
     } 

    }; 
    button1.setOnClickListener(myListener); 
    button2.setOnClickListener(myListener); 
0

我可以想象你如何能夠陷入這個麻煩。我認爲你應該使用IDE來幫助你編寫代碼。 IDE會告訴你如何解決它。