Learning Native Droid

of 4
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Documents

Published:

Views: 3 | Pages: 4

Extension: PDF | Download: 0

Share
Description
Description:
Tags
Transcript
  Learning Native Droid - Part I (Activity & Layout) Case 1 : Form Login Layout : ActivityMain.xml <TableLayout xmlns:android= http://schemas.android.com/apk/res/android  android:layout_width= fill_parent  android:layout_height= fill_parent  android:stretchColumns= 1 > <TableRow>  <TextView android:text= User Name:  android:id= @+id/TextView01  android:layout_width= wrap_content  android:layout_height= wrap_content > </TextView>  <EditText android:text=  android:id= @+id/txtUname  android:layout_width= fill_parent  android:layout_height= wrap_content > </EditText>  </TableRow>  <TableRow>  <TextView android:text= Password:  android:id= @+id/TextView02  android:layout_width= wrap_content  android:layout_height= wrap_content > </TextView>  <EditText android:text=  android:id= @+id/txtPwd  android:layout_width= fill_parent  android:layout_height= wrap_content  android:password= true > </EditText>  </TableRow>  <TableRow>  <Button android:text= Cancel  android:id= @+id/btnCancel  android:layout_width= fill_parent  android:layout_height= wrap_content > </Button>  <Button android:text= Login  android:id= @+id/btnLogin  android:layout_width= fill_parent  android:layout_height= wrap_content > </Button>  </TableRow>  </TableLayout>      Activity : MainActivity.java  package  com.example.hello_world; import  android.os.Bundle; import  android.app.Activity; 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 { EditText txtUserName, txtPassword; String UserName= dian , Password= yolo ; Button btnLogin, btnCancel; @Override   protected    void   onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); initView(); } @Override   public    boolean  onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu. main , menu); return   true ; }  private   void   initView(){ txtUserName=(EditText) this .findViewById(R.id. txtUname ); txtPassword=(EditText) this .findViewById(R.id. txtPwd  ); btnLogin=(Button) this .findViewById(R.id. btnLogin ); btnLogin.setOnClickListener( new  OnClickListener() { @Override   public   void   onClick(View v) { if ((txtUserName.getText().toString()).equals(UserName)){ if ((txtPassword.getText().toString()).equals(Password)){ Toast. makeText (MainActivity. this , Login Success ,Toast. LENGTH_LONG  ).show(); } else  Toast. makeText (MainActivity. this , Invalid Login - Wrong Password ,Toast. LENGTH_LONG  ).show(); } else { Toast. makeText (MainActivity. this , Invalid Login - Wrong Username ,Toast. LENGTH_LONG  ).show(); } } }); btnLogout=(Button) this .findViewById(R.id. btnLogout ); btnLogout.setOnClickListener( new  OnClickListener() { @Override   public   void   onClick(View v) { setContentView(R.layout. activity_main ); }   }); } } Output Case 2 : Form Setelah Login Layout : Bonjour.xml <TableLayout xmlns:android= http://schemas.android.com/apk/res/android  android:layout_width= fill_parent  android:layout_height= fill_parent  android:stretchColumns= 1 > <TableRow>  <TextView android:text= Selamat Datang  android:id= @+id/TextView01  android:layout_width= wrap_content  android:layout_height= wrap_content > </TextView>  <TextView android:text=  android:id= @+id/TextView02  android:layout_width= wrap_content  android:layout_height= wrap_content > </TextView>  </TableRow>  <TableRow>  <Button android:text= Log Out  android:id= @+id/btnLogout  android:layout_width= fill_parent  android:layout_height= wrap_content > </Button>  </TableRow>   </TableLayout>   Output
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x