私のアプリケーションでは、ネットワークのデータに応じてUIのテキストを更新する必要があります。そのためには、AsyncTask
をバックグラウンドで使用していますアンドロイド。私のコードは以下の通りです。私はテキストがUIに更新されていないfalse.Butとしてブール値を取得するまでのバックグラウンドスレッドを実行することができています上記のコードでUIのテキストをAndroidのバックグラウンドスレッドから更新する方法
public class DefaultActivity extends Activity{
TextView textView;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView=(TextView)findViewById(R.id.textId);
new networkFileAccess().execute("background","Progress","result");
}
private class networkFileAccess extends AsyncTask<String,String,String>{
protected String doInBackground(String... background){
return changeText();
}
private String changeText(){
//Code to Access data from the Network.
//Parsing the data.
//Retrieving the boolean Value.
if(booleanistrue){
//Displaying some text on the UI.
publishProgress("someTextOnUI");
//Send request till we get get boolean value as false.
changeText();
}else{
return "success";
}
return "";
}
protected void onProgressUpdate(String... progress){
textView.setText("Wait background work is going on");
}
protected void onPostExecute(String result){
if(result.equals("success")){
//Code to finish the activity.
}
}
}
}
。 onProgressUpdate
()メソッドを使用してUIのテキストを更新することはできますか?publishProgress
メソッドを呼び出すことができます。
ありがとうございました。 – user1195614