Bar plot Example

MainActivity.java
============
package engles.studentapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    String sem[]={"sem-3","sem-4","sem-5","sem-6"};
    String subsem3[]={"Java","SSOS","PHP","BM"};
    String subsem4[]={"SE","R","Android","FON"};
    String subsem5[]={"ASP.NET","VB","C","C++"};
    String subsem6[]={"Project"};
    Spinner s1,s2;
    EditText ed;
    Button b1;
    RadioGroup rg;
    RadioButton rb1,rb2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        s1= (Spinner) findViewById(R.id.spinnersem);
        s2= (Spinner) findViewById(R.id.spinnersub);
        b1= (Button) findViewById(R.id.button1);
        ed= (EditText) findViewById(R.id.txtname);
        rg=findViewById(R.id.);
        ArrayAdapter<String> a=
                new ArrayAdapter<String>
                        (getApplicationContext(),R.layout.support_simple_spinner_dropdown_item,sem);
        s1.setAdapter(a);

        s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                //Toast.makeText(getApplicationContext(), ""+position, Toast.LENGTH_SHORT).show();
                if(position==0){
                    ArrayAdapter<String> a=
                            new ArrayAdapter<String>
                                    (getApplicationContext(),R.layout.support_simple_spinner_dropdown_item,subsem3);
                    s2.setAdapter(a);
                }
                if(position==1){
                    ArrayAdapter<String> a=
                            new ArrayAdapter<String>
                                    (getApplicationContext(),R.layout.support_simple_spinner_dropdown_item,subsem4);
                    s2.setAdapter(a);
                }
                if(position==2){
                    ArrayAdapter<String> a=
                            new ArrayAdapter<String>
                                    (getApplicationContext(),R.layout.support_simple_spinner_dropdown_item,subsem5);
                    s2.setAdapter(a);
                }
                if(position==3){
                    ArrayAdapter<String> a=
                            new ArrayAdapter<String>
                                    (getApplicationContext(),R.layout.support_simple_spinner_dropdown_item,subsem6);
                    s2.setAdapter(a);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name=ed.getText().toString();

                Toast.makeText(getApplicationContext(), "Studenet NAme Is: "+name, Toast.LENGTH_SHORT).show();

            }
        });

    }
}
================================================================
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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="engles.studentapp.MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:id="@+id/txtname"
        android:hint="Enter Student Name" />



    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/txtname"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="12dp">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textview"
                android:text="Gender:"
                android:textSize="20dp"
                />
            <RadioGroup android:id="@+id/rg1">
                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Male"
                    android:id="@+id/r1"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Female"
                android:id="@+id/r2"/>
            </RadioGroup>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView
                android:id="@+id/textsem"
                android:text="Semester"
                android:textSize="20dp"/>
            <Spinner
                android:id="@+id/spinnersem"
                android:layout_height="wrap_content"
                android:layout_width="100dp"/>

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView
                android:id="@+id/textsub"
                android:text="Subject"
                android:textSize="20dp"/>
            <Spinner
                android:id="@+id/spinnersub"
                android:layout_height="wrap_content"
                android:layout_width="50dp"/>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <Button
                android:text="Button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="139dp"
                android:id="@+id/button1"
                />
        </TableRow>

    </TableLayout>
    <![CDATA[




    />
]]>
</RelativeLayout>
==================================

No comments:

Post a Comment

Unleashing B2B Success: Mastering Event and Conversion Tracking with GA4

Tracking events and conversions is vital for B2B businesses using GA4 (Google Analytics 4) to optimize their marketing efforts. Here is a re...