Androidの初心者です.JSONからテキストと画像を表示したい...ここではテキストは表示できますが、画像は表示できません...誰か助けてくれますか??
This is my JSON :
{
" countries":[
{"countryname":"India",
"flag":"http://******.in/p/demo1/india.png" },
{"countryname":"****",
"flag":"http://******.in/p/demo1/*****.png" },
...........................................and so on
]
}
ここで国名を表示できますが、画像(旗)を表示できません...リストビューに表示される国名と旗....項目をクリックすると、国名とその国名が表示されます別のアクティビティのフラグ....国名を取得しますが、イメージビューのフラグは取得しません....
ここに私のコード:
public class AndroidJSONParsingActivity extends ListActivity {
// url to make request
private static String url = "http://*****@#$$$@#$.in/p/demo1/first.php/countries";
// JSON Node names
private static final String TAG_COUNTRIES = "countries";
private static final String TAG_COUNTRYNAME = "countryname";
private static final String TAG_FLAG= "flag";
JSONArray countries = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
countries = json.getJSONArray(TAG_COUNTRIES);
// looping through All Contacts
for(int i = 0; i < countries.length(); i++){
JSONObject c = countries.getJSONObject(i);
// Storing each json item in variable
String name = c.getString(TAG_COUNTRYNAME);
String flag= c.getString(TAG_FLAG);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_COUNTRYNAME, id);
map.put(TAG_LANGUAGE, name);
map.put(TAG_CAPITAL, email);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(this, contactList,R.layout.list_item,
new String[] { TAG_COUNTRYNAME, TAG_FLAG}, new int[] {
R.id.country_name, R.id.flag});
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String country_name = ((TextView) view.findViewById(R.id.countyr_name)).getText().toString();
String flag= ((ImageView) view.findViewById(R.id.flag)).getTag().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(TAG_COUNTRYNAME, country_name);
in.putExtra(TAG_FLAG, flag);
startActivity(in);
}
});
}
}