Create a radio button group with radio button of all courses in your college and on selecting a particular course, teacher-in-charge of that course should appear at the bottom of the screen.

/* Create a radio button group with radio button of all courses in your college and on selecting a particular course, teacher-in-charge of that course should appear at the bottom of the screen.*/

File Name: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rg1">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Night mode App"
            android:id="@+id/RB1"/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Eye Filter App"
            android:id="@+id/RB2"
            android:layout_centerHorizontal="true" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Night Screen Mode"
            android:layout_alignParentRight="true"
            android:id="@+id/RB3"/>
    </RadioGroup>

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="500dp"
        android:textSize="35dp"
        android:layout_centerHorizontal="true"
        android:id="@+id/T1"/>

</RelativeLayout>    

File Name: MainActivity.java

package com.ducskecode.radio_example;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    private RadioGroup rgrp;
    private RadioButton r1,r2,r3;
    private TextView t1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   rgrp = (RadioGroup) findViewById(R.id.rg1);
   r1=(RadioButton)findViewById(R.id.RB1);
   r2=(RadioButton)findViewById(R.id.RB2);
   r3=(RadioButton)findViewById(R.id.RB3);
   t1= (TextView)findViewById(R.id.T1);

   rgrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
     public void onCheckedChanged(RadioGroup group, int checkedId) {

     RadioButton nameRadio = (RadioButton) findViewById(checkedId);

     String s1=nameRadio.getText().toString();

     if(checkedId==r1.getId())
                {
                    String s2="Parikshit android class";
                    t1.setText(s2);
                }
                else if(checkedId==r2.getId()) {
                String s3="Parikshit c++ class";
                    t1.setText(s3);
                }
                else{
                    String s4="Parikshit system programming class";
                    t1.setText(s4);
                }
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}        

No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...