Professional Documents
Culture Documents
How To Check Radiobuttun With Options
How To Check Radiobuttun With Options
How To Check Radiobuttun With Options
<RadioGroup
android:id="@+id/G"
android:layout_width="match_parent"
android:layout_height="133dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="113dp"
android:text="A"
android:textSize="40sp" />
<RadioButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="B"
android:textSize="40sp" />
<RadioButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="C"
android:textSize="40sp" />
<RadioButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="D"
android:textSize="40sp" />
</RadioGroup>
</RelativeLayout>
Main.java
package com.example.androidapps.myapplicationre;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.Toast;
import org.w3c.dom.Text;
RadioGroup G;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
G.findViewById(R.id.G);
G.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case 1:
{
Toast.makeText( MainActivity.this,
"A",Toast.LENGTH_SHORT).show();
break;
}
case 2:
{
Toast.makeText(MainActivity.this,"B",Toast.LENGTH_SHORT).show();
break;
}
case 3:
{
Toast.makeText(MainActivity.this,"C",Toast.LENGTH_SHORT).show();
break;
}
case 4:
{
Toast.makeText(MainActivity.this,"C",Toast.LENGTH_SHORT).show();
break;
}
}
}
});
}
}
editeeted xml
<RadioGroup
android:weightSum="20"
android:id="@+id/G"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_weight="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A"
android:textSize="40sp" />
<RadioButton
android:layout_weight="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="B"
android:textSize="40sp" />
<RadioButton
android:layout_weight="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="C"
android:textSize="40sp" />
<RadioButton
android:layout_weight="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="D"
android:textSize="40sp" />
</RadioGroup>
</RelativeLayout>