Pertama kita harus mengistasl Eclipsenya terlebih dalu tetapi disini saya tidak menjelaska bagamna cara mngisntal eclipse:)
-Disini saya akan buat activiti yaitu
- Main Activity
- Failed Activity
- Success Avtivity
- Buat nama project Form Login
- setelah itu kamu bisa mengganti warna (ssuia dengan yang kamu ingin kan)
-next
-finish
-Tambahkan Failed Activity & Success Activity seperti main activityy yang di atas
- nah dan sekarang kita akan mebuat tampilan awal from loginnya
Gambar.Tampilan Main Activity
Gambar. Tampilan Failed Activity
Gambar.Tampilan Succes Activity
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener{
private String[][] dataUser = {{"SINTA","SINTA","Administrator"},
{"user1","password1","Nama User 1"},
{"user2","password2","Nama User 2"}};
private EditText userNameET, passwordET;
private final int SUCCESS=1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userNameET = (EditText) findViewById(R.id.userNameEditText);
passwordET = (EditText) findViewById(R.id.passwordEditText);
findViewById(R.id.loginButton).setOnClickListener(this);
findViewById(R.id.tutupButton).setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.loginButton:
int i=0;
boolean success=false;
while ((i<dataUser.length) && (!success)){
if
((userNameET.getText().toString().equals(dataUser[i][0])) &&
(passwordET.getText().toString().equals(dataUser[i][1]))){
success=true;
} else {
i++;
}
}
Intent intent;
if (success){
intent = new Intent(this, SuccessActivity.class);
intent.putExtra("namaUser", dataUser[i][2]);
startActivityForResult(intent,SUCCESS);
} else {
intent = new Intent(this, FailedActivity.class);
startActivity(intent);
}
startActivity(intent);
break;
case R.id.tutupButton:
System.exit(0);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
switch (requestCode) {
case SUCCESS:
userNameET.setText("");
passwordET.setText("");
break; }
}
}
- codingan untuk Failed Activity
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
public class FailedActivity extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_failed);
findViewById(R.id.kembaliButton).setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_failed, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.kembaliButton:
finish();
}
}
}
- condingan untuk suscess
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class SuccessActivity extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_success);
TextView namaUserTV = (TextView)
findViewById(R.id.namaUserTextView);
namaUserTV.setText( getIntent().getExtras().getString("namaUser"));
findViewById(R.id.logoutButton).setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_success, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.logoutButton:
finish();
}
}
}
- setelah itu saya akan mengRun project Form Login Yang telah kita buat
Gambar Tampilan Form Login
Gambar Tampilan Failed Activity
Gambar Tampilan Succes Activity
SEMOGA BERHASIL TEMAN-TEMAN :)
Tidak ada komentar:
Posting Komentar