【发布时间】:2014-10-01 13:49:33
【问题描述】:
嘿,很棒的编码天才!我是一名学生,正在做我最后一年的项目,我需要一些帮助。我希望你编码天才可以帮助! 单击登录按钮后,我想将我的 Login.java 页面定向到我的 Camera.java。我的xml页面分别是Login.xml和Camera.xml。
这是我的 Login.java
public class Login extends Activity {
private EditText username=null;
private EditText password=null;
private TextView attempts;
private Button login;
int counter = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
username = (EditText)findViewById(R.id.editText1);
password = (EditText)findViewById(R.id.editText2);
attempts = (TextView)findViewById(R.id.textView5);
attempts.setText(Integer.toString(counter));
login = (Button)findViewById(R.id.button1);
}
public void login(View view){
if(username.getText().toString().equals("amirul") &&
password.getText().toString().equals("aswa")){
Toast.makeText(getApplicationContext(), "Redirecting...",
Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "Wrong Credentials, Please try again.",
Toast.LENGTH_SHORT).show();
attempts.setBackgroundColor(Color.RED);
counter--;
attempts.setText(Integer.toString(counter));
if(counter==0){
login.setEnabled(false);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这是我的 Camera.java
public class Camera extends Activity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
iv = (ImageView) findViewById(R.id.imageView);
Button btn = (Button) findViewById(R.id.takephoto);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode ==0) {
Bitmap theImage = (Bitmap) data.getExtras().get("data");
iv.setImageBitmap(theImage);
}
}
}
我希望你们能帮助我!顺便说一句,这是我的第一篇文章!
【问题讨论】: