2017-12-01 2 views
0

나는 두 개의 단추가 있고 폴더에 파일이 없으면 버튼 단추를 사용하지 못하게하려고합니다. 그러나 문제는 단추 설치가 항상 해제되어 있습니다 .. 왜?클릭 버튼을 비활성화하는 방법은 무엇입니까?

 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); 
    } 
+0

내 대답을 확인하십시오. – diegoveloper

답변

0

당신이 :

에서 onCreate 방법 :

Button install = (Button) findViewById(R.id.install); 
    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); 
      } 

     }); 

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(file.exists()); 
     } 
+0

하하 .. 나는 약 2 시간을 풀려고하고 있으며 해결책은 간단합니다. 설명했다 .. 고마워 :) – ahmed3

+0

문제가 형제, 최대 투표를 잊지 마세요;) – diegoveloper

+0

확인 :) ... 완료 .. – ahmed3

관련 문제