だから私は、ユーザ名が画像の名前に対応するテーブルを持つデータベースを持っています。私のAsyncHTTPではUsernameを取得し、そのUsernameを正しいイメージにマッピングしたい(すべてのイメージは私のdrawableフォルダにあります)非同期で画像を更新する
私のXMLでは、このイメージがレンダリングされる場所にイメージビューを置き、画像(このimageViewのIDはmyImageです)
コードを実行すると、画像はレンダリングされません。スコープの問題のために、非同期以外のイメージを割り当てることはできません。
Context context = this;
AsyncHTTPPost asyncHttpPost2 = new AsyncHTTPPost(
"http://lamp.ms.wits.ac.za/~s1363679/avatars.php", params) {
@Override
protected void onPostExecute(String s) {
try {
JSONArray all = new JSONArray(s);
for (int i = 0; i < all.length(); i++) {
JSONObject item = all.getJSONObject(i);
fName = item.getString("avatarName");
System.out.println();
Toast.makeText(Profile.this, fName, Toast.LENGTH_LONG).show();
ImageView Image = (ImageView) findViewById(R.id.myImage);
System.out.println("");
theName = fName;
//String imagename="kaius";
Resources res = context.getResources();
int resID = res.getIdentifier(theName, "drawable", context.getPackageName());
Image.setImageResource(resID);
}
} catch (Exception e) {
Toast.makeText(Profile.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
};
asyncHttpPost2.execute();
}
imageNameは正しく検索され、変数 "theName"に格納されますが、ビューには表示されません。あなたの描画可能なフォルダの同じレベルに