res>layout>activity_log_main.xml
<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"
tools:context=".LogMainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:text="Name" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="28dp"
android:text="Password" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView2"
android:layout_marginRight="15dp"
android:ems="10" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignLeft="@+id/editText2"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginLeft="58dp"
android:layout_marginTop="28dp"
android:text="Button" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignTop="@+id/button1"
android:layout_marginLeft="22dp"
android:layout_marginTop="32dp"
android:src="@drawable/ic_sel" />
</RelativeLayout>
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
src>LogMainActivity
package com.example.loginusers;
import android.os.Bundle;
import com.example.loginusers.R;
import android.widget.EditText;
import android.widget.Button;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.view.*;
public class LogMainActivity extends Activity {
private EditText edit,edit1;
private Button but;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_main);
addKeyListener();
}
public void addKeyListener()
{
edit= (EditText) findViewById(R.id.editText1);
edit1= (EditText) findViewById(R.id.editText2);
but=(Button) findViewById(R.id.button1);
but.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String a=(edit.getText().toString());
String b=(edit1.getText().toString());
if(a.equals("arun") && b.equals("arun"))
{
Intent i = new Intent(LogMainActivity.this, Mainfun.class);
startActivity(i);
}
else
{
Toast.makeText(LogMainActivity.this,"please enter valid details", Toast.LENGTH_LONG).show();
}
}
});
}
}
Mainfun.java
package com.example.loginusers;
import android.app.Activity;
import com.example.loginusers.R;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.*;
import android.widget.Button;
import android.widget.TextView;
public class Mainfun extends Activity{
private Button but1;
private TextView text3;
private int count=0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addKeyListener();
}
public void addKeyListener()
{
but1=(Button) findViewById(R.id.button1);
text3=(TextView)findViewById(R.id.textView10);
but1.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
count++;
text3.setText("you are the" +count);
}
});
}
}
Android Mainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginusers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.loginusers.LogMainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Mainfun"
android:label="Welcome"></activity>
</application>
</manifest>
Output:
No comments:
Post a Comment