2017-11-27 4 views
0

私のアプリケーションクラスとDBHelperクラスのメソッドの回答を比較しようとしています。私は活動でこれを行います。アクティビティ内のアプリケーションからメソッドを使用する方法

public class thing extends Application { 

      private String thing1; 
      private String thing2; 
      private String thing3; 
      private String thing4; 


      public String getVariable() { 
        return thing1 + thing2 + thing3 + thing4;      
      } 

マイアクティビティ:

あなたが使用することができます
  public class solution extends AppCompatActivity { 

       protected DBHelper DB; 
        @Override 
       protected void onCreate(Bundle savedInstanceState) { 
       ... 
        } 

        } 


      final Button solution = findViewById(R.id.solutionbutton); 

      sol.setOnClickListener(new View.OnClickListener() { 
       public void onClick(View v) { 
         DBHelper db = new DBHelper(getApplicationContext()); 
         if(db.getDODO("two").equals(thing.getVariable())){ 
          .... 
         } 
     }); 
     }} 
+1

'thing'は静的クラスではなく、' getVariable() 'は静的メソッドではありません。そのため、あなたは 'getVariable()'を呼び出すことができません – rguessford

答えて

0

私はDBHelperクラスのメソッドを使用できますが、私は私のApplicationクラスのメソッド

私のアプリケーションクラスにアクセスすることはできません

((thing) getApplication()).getVariable(); 
関連する問題