我的布局中有两个按钮,
现在我需要的是,我想启用" buttonLoadImage"如果用户onclick" buttonAddImage" else" buttonLoadImage"总是禁用。如何帮助我。
final Button buttonAddImage = (Button) findViewById(R.id.buttonAddPicture);
final Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
buttonAddImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonLoadImage.setEnabled(true);
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
答案 0 :(得分:2)
在onClick方法
之外添加禁用按钮的代码 final Button buttonAddImage = (Button) findViewById(R.id.buttonAddPicture);
final Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setEnabled(false);
buttonAddImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonLoadImage.setEnabled(true);
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
答案 1 :(得分:0)
尝试在buttonAddImage
的onclick中设置buttonLoadImage的监听器 @Override
public void onClick(View view) {
buttonLoadImage.setOnClickListener(this);
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
答案 2 :(得分:0)
使用此
final Button buttonAddImage = (Button) findViewById(R.id.buttonAddPicture);
final Button buttonLoadImage = (Button)findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setEnabled(false);
buttonAddImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonLoadImage.setEnabled(true);
}
答案 3 :(得分:0)
像你这样在你的班级中定义变量
private boolen ISCLICKED=false;
d
然后
buttonAddImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
ISClLICKED=true
}
});
现在点击检查按钮
if(ISCLICKED==true){
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//do somththing
}
});
}else
{
Toast.maketext(contex,"Add image 1st",Toast.LENGHT_SHORT).show;
}