You are on page 1of 2

package com.voter; import com.voter.R ; import import import import import import import import import android.os.Bundle; android.app.

Activity; android.view.Menu; android.view.View; android.view.View.OnClickListener; android.widget.Button; android.widget.EditText; android.widget.TextView; android.widget.Toast;

public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnclickme = (Button)findViewById(R.id.btnclickme); final TextView lblenterage=(TextView)findViewById(R.id.lblenterage); final EditText textage = (EditText)findViewById(R.id.textage); btnclickme.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String value = textage.getText().toString(); int age = Integer.parseInt(value); if(age>=18) Toast.makeText(MainActivity.this, "You are eligible",Toast.LENGTH_LONG).show(); else Toast.makeText(MainActivity.this, "You are not eligible",Toast.LENGTH_LONG).show(); ; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }

XML
<LinearLayout 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:orientation="vertical" 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=".MainActivity" > <TextView android:id="@+id/lblenterage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Enter your age??" android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText android:id="@+id/textage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="numberPassword" > <requestFocus /> </EditText> <Button android:id="@+id/btnclickme" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Check" /> <TextSwitcher android:id="@+id/textSwitcher1" android:layout_width="match_parent" android:layout_height="wrap_content" > </TextSwitcher> </LinearLayout>

You might also like