Académique Documents
Professionnel Documents
Culture Documents
<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;
@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;
}
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
<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