Creating the login page for the sqlite database when you are entering the login the page you should type the username and password ,so then we should check your Authentication. here we the following example will helpful to creating login page.
write the following code in your main class:
package com.loginpage;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
Button b;
TextView tv1,tv2;
EditText ed1,ed2;
String name,passlock;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button1);
ed1=(EditText)findViewById(R.id.editText1);
ed2=(EditText)findViewById(R.id.editText2);
tv1=(TextView)findViewById(R.id.textView1);
tv2=(TextView)findViewById(R.id.textView2);
b.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
name=ed1.getText().toString();
passlock=ed2.getText().toString();
Toast.makeText(this, "name ::"+name+"pass:"+passlock, Toast.LENGTH_LONG).show();
/* tv1.setText(passlock);
tv2.setText(name);*/
tv1.append(name);
tv2.append(passlock);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.main,menu);
// adding items
menu.add(1, 1, 1, "call").setIcon(R.drawable.ic_launcher);
menu.add(1, 2, 2, "Message");
return super.onCreateOptionsMenu(menu);
}
}
in your main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ccddee" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/usr" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:hint="@string/pas" android:layout_height="wrap_content" android:inputType="textPassword" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/but" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/usernameeee" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/password" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout>
output :
write the following code in your main class:
package com.loginpage;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
Button b;
TextView tv1,tv2;
EditText ed1,ed2;
String name,passlock;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button1);
ed1=(EditText)findViewById(R.id.editText1);
ed2=(EditText)findViewById(R.id.editText2);
tv1=(TextView)findViewById(R.id.textView1);
tv2=(TextView)findViewById(R.id.textView2);
b.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
name=ed1.getText().toString();
passlock=ed2.getText().toString();
Toast.makeText(this, "name ::"+name+"pass:"+passlock, Toast.LENGTH_LONG).show();
/* tv1.setText(passlock);
tv2.setText(name);*/
tv1.append(name);
tv2.append(passlock);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.main,menu);
// adding items
menu.add(1, 1, 1, "call").setIcon(R.drawable.ic_launcher);
menu.add(1, 2, 2, "Message");
return super.onCreateOptionsMenu(menu);
}
}
in your main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ccddee" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/usr" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:hint="@string/pas" android:layout_height="wrap_content" android:inputType="textPassword" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/but" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/usernameeee" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/password" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout>
output :
No comments:
Post a Comment