2012-02-24 8 views
0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Text1" /> 


<CheckBox 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/check" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
    /> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Text2" /> 

<RadioGroup 
    android:id="@+id/rg" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<RadioButton android:id="@+id/radio1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Mazda" /> 
<RadioButton android:id="@+id/radio2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Toyota" /> 
<RadioButton android:id="@+id/radio3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Nissan" /> 
<RadioButton android:id="@+id/radio4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hyundai" /> 
    </RadioGroup> 

    <EditText 
     android:inputType="text|textMultiLine" 
android:id="@+id/etext1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
></EditText> 



<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

</LinearLayout> 

    package nidhin.survey; 

import android.app.Activity; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.*; 
import android.os.Bundle; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.TextView; 

public class SurveyActivity extends Activity implements OnCheckedChangeListener 

{ 
CheckBox cb; 
String myChoice; 

RadioButton radio1; 
RadioButton radio2; 
RadioButton radio3; 
RadioButton radio4; 
RadioGroup rg; 
EditText text1; 

public void onCreate(Bundle savedInstanceState) 

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

    cb=(CheckBox)findViewById(R.id.check); 
    cb.setOnCheckedChangeListener(this); 
    rg=(RadioGroup)findViewById(R.id.rg); 
    radio1=(RadioButton)findViewById(R.id.radio1); 
    radio2=(RadioButton)findViewById(R.id.radio2); 
    radio3=(RadioButton)findViewById(R.id.radio3); 
    radio4=(RadioButton)findViewById(R.id.radio4); 
    text1=(EditText)findViewById(R.id.etext1); 
    text1.setText(myChoice); 
} 



    cb=(CheckBox)findViewById(R.id.check); 
    cb.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    { 
    public void onCheckedChanged(CompoundButton buttonView, 
     boolean isChecked) 
     { 
       if (isChecked) 
       { 
       cb.setText("This checkbox is: checked"); 
       } 
       else 
       { 
       cb.setText("This checkbox is: unchecked"); 
       } 
     } 
    } 
    ); 


    setContentView(R.layout.main); 

    Button1=(Button)findViewById(R.id.button); // through XML file 
    Button1.setText("Click to display updated time"); 


    Button2=(Button)findViewById(R.id.button2); 
    Button2.setText("Not Pressed yet"); 

    Button3=(Button)findViewById(R.id.button3); 
    Button3.setText("Press for image"); 

} 

public void myButton1 (View view) 
{ 
updateTime(); 
} 

public void myButton2 (View view) 
{ 

Button2.setText("Pressed"); 
} 

public void myButton3 (View view) 
{ 
    image = (ImageView)findViewById(R.id.image); 
image.setVisibility(View.VISIBLE);//image.setVisibility(1); 
} 



private void updateTime() 
{ 
    Button1.setText(new Date().toString()); 
} 
} 

私はチェックボックス、radiogroup、editTextボックスを表示するプログラムを持っています。しかし問題は、編集テキストボックスが表示されないことです。 CheckedBoxとラジオボタンが表示されますが、テキストボックスは編集されません。 main.xmlファイルで、彼がradiogroupの上にeditTextボックスを置くと、プログラムがクラッシュします。テキストが正しく宣言されていないか編集しますか?editTextを表示しようとしてエラーが発生しました

答えて

1

に変更してください、あなたのラジオ・あなたはlayout_height属性のfill_parentとして使用

  <RadioGroup 
android:id="@+id/rg" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
> 

に属性を変更してください。

1

android:layout_heightfill_parentあるRADIOGROUP ATTS、wrap_content

関連する問題