2017-04-16 10 views
0

私は、データベースから受け取った日付を表示するアクティビティを持っています。 私の結果をTextViewに表示しても問題ありません。しかし、私はまた、受け取ったデータをString値に保存したい。 マイコード: 主な活動:Android Studio AsyncTask他のアクティビティへの結果を取得

db3 = new DatabaseC529(C529chooseActivity.this,tvC529Cthirdoccupied,tInt3); 
db3.execute(methode, date, timeId3); 

DatabaseC529: コンストラクタ:AsyncTask後

public DatabaseC529(Activity activity, TextView textView, String myValue){ 
     this.activity = activity; 
     this.ctx = activity; 
     this.textView = textView; 
     this.myValue = myValue;} 

...

protected void onPostExecute(String result) {super.onPostExecute(result); 
this.textView.setText(result); 
this.myValue = result; 
} 

が完了しているが、結果はTextViewの中で示されています。 しかし、私はまた、 "tInt3"という文字列に値を格納したいと思っています。 AsyncTaskが完了した後にtInt3の内容を取得するためのボタンを作成しましたが(値が格納されているかどうかを確認するだけです)、常に「null」と表示されます。 コードボタン:

public void button1 (View view){if(view.getId() == R.id.button1){ 
     Toast.makeText(this, " " +tInt3, Toast.LENGTH_SHORT).show(); 
    } 

誰かが私を助けてください???

+0

? –

+0

AsyncTaskが別のクラスであるため、[OnPostExecute()の結果をメインアクティビティに取得する方法]の可能な複製?](http://stackoverflow.com/questions/12575068/how-to-get-the-result-of- onpostexecute-to-main-activity-asynctask-is-a) –

+0

インターフェイスを作成してくれてありがとう、問題を解決しました –

答えて

0

共有設定を使用すると、文字列データを格納して使用できます。

保存値:

SharedPreferences.Editor editor = getSharedPreferences(yourpref, MODE_PRIVATE).edit(); 
editor.putString("tInt3", Result); 
editor.apply(); 

は、値の取得:あなたはtInt3に値を格納している

SharedPreferences prefs = getSharedPreferences(yourpref, MODE_PRIVATE); 
String value= prefs.getString("tInt3", "null"); 
関連する問題