나는 두 개의 단추가 있고 폴더에 파일이 없으면 버튼 단추를 사용하지 못하게하려고합니다. 그러나 문제는 단추 설치가 항상 해제되어 있습니다 .. 왜?클릭 버튼을 비활성화하는 방법은 무엇입니까?
Button install = (Button) findViewById(R.id.install);
final File file_1 = new File(Environment.getExternalStorageDirectory() + "/download/app-debug.apk");
if(file_1.exists()){
install.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/"+"app-debug.apk")),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}else {
install.setEnabled(false);
}
}
추가 할 경우 install.setEnabled (false); 작업 .. onResume()에있는 버튼은 모든 시간을 사용하지 않도록 설정하지만, 경우에하는 것은 onResume()에서 삭제 좋은 여기 :(
@Override
public void onResume() {
super.onResume();
final File file = new File(Environment.getExternalStorageDirectory() + "/download/app-debug.apk");
final Button down = (Button) findViewById(R.id.down);
down.setEnabled(!file.exists());
final Button install = (Button) findViewById(R.id.install);
install.setEnabled(false);
}
내 대답을 확인하십시오. – diegoveloper