Posted by Shoaib at 6:13:00 pm
Read our previous post
Layout/activity_main:
<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"> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPersonName" android:ems="10" android:id="@+id/edtuser" android:layout_alignParentTop="true" android:layout_alignLeft="@+id/edtpass" android:layout_alignStart="@+id/edtpass" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:ems="10" android:id="@+id/edtpass" android:layout_marginTop="75dp" android:layout_below="@+id/edtuser" android:layout_alignLeft="@+id/btnLogin" android:layout_alignStart="@+id/btnLogin" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Login" android:id="@+id/btnLogin" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="UserName" android:id="@+id/textView" android:layout_alignBottom="@+id/edtuser" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Pass" android:id="@+id/textView2" android:layout_alignBottom="@+id/edtpass" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
MainActivity.java:
package com.example.shoaibm.loginsimple2; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends ActionBarActivity { Button button; EditText edt1, edt2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edt1 = (EditText)findViewById(R.id.edtuser); edt2 = (EditText)findViewById(R.id.edtpass); button = (Button)findViewById(R.id.btnLogin); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(edt1.getText().toString().equals("user") && edt2.getText().toString().equals("pass")) { Toast.makeText(getApplicationContext(), "Registered User", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),"Incorrect Username and Password", Toast.LENGTH_LONG).show(); } } }); } }
No comments:
Post a Comment