【发布时间】:2014-08-27 21:53:56
【问题描述】:
尝试在我的片段中的 AsyncTask 中设置 EditText 中的文本。这在我的其他课程中效果很好,但片段让我失望。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profile_fragment_main, container,
false);
new getinfo().execute();
if (emailTwo != null) {
email2.setText(emailTwo);
}
if (emailThree != null) {
email3.setText(emailThree);
}
if (mailingaddress1 != null) {
mail1.setText(mailingaddress1);
}
} // end of onCreate
class getinfo extends AsyncTask<String, String, String> {
// onPreExecute() and onPostExecute here
@Override
protected String doInBackground(String... args) {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", restoredemail));
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
params);
success = json.getInt(TAG_SUCCESS);
if (success == 2) {
emailTwo = json.getString("secondemail");
emailThree = json.getString("thirdemail");
mailingaddress1 = json.getString("mailingaddress1");
return json.getString(TAG_MESSAGE);
} else {
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
任何帮助将不胜感激。我尝试将 editText .setText 放在 onPostExecute 中,但片段不允许这样做。我也尝试返回值,但它只允许一项。
【问题讨论】:
标签: android android-fragments android-asynctask