2017-12-01 19 views
0

私は2つのボタンを持っていて、ファイルがフォルダ内に存在しない場合はクリックボタンの実行を無効にしたいですが、ボタンのインストールはいつも無効になっています..なぜですか?クリックボタンを無効にするにはどうすればよいですか?

 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

ok :) ...完了.. – ahmed3

関連する問題