doInBackgroundメソッドを使用AsyncTaskして Web サーバーにメッセージを送信しようとして います。次に、 onPreExecute()およびonPostExecute(String result)メソッドを使用してAsyncTask、テキスト コントロールを変更して、データを Fineshed に送信します。
問題は、AsyncTask String クラス内で、外部クラスで宣言された変数にアクセスできないことです。したがって、これらのメソッド内で TextView を変更することはできません。mSEnd.setText("Sending data")私は得るので、 mSend未定義になります。
外部クラスで宣言した変数を使用する方法はありますか?
public class EndOfWorldActivity extends cBase implements OnClickListener {
TextView textCountDown;
TextView textPercent;
public void onClick(View v) {
Intent i;
switch(v.getId())
{
case R.id.butVote3:
// Start ASync Task
new SendTextOperation().execute("");
break;
case R.id.buGame:
// Start ASync Task
new SendTextOperation().execute("");
break;
}
}
private class SendTextOperation extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
//Update UI here
mSEnd undefined error
mSend.setText("Sending your vote to server");
mSend.invalidate();
}
@Override
protected String doInBackground(String... params) {
// Talk to server here to avoid Ui hanging
// talk to server method undefined
TalkToServer( mYes[mPes-1] );
return null;
}
@Override
protected void onPostExecute(String result) {
// Update screen here after talk to server end
UpdateScreen();
mSend .setText("");
}
}
} // end of class