Я начинаю с android .. Я хочу отобразить текст и изображение из JSON ... Здесь я могу отображать текст, но не изображение ... Может ли кто-нибудь мне помочь? ??как показать изображение с объекта 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
]
}
Здесь я могу отобразить COUNTRYNAME, но косяк, способный отображать изображения (флаг) ... Страну имени и отображаемый в виде в списке флаг .... если я нажимаю по любому вопросу, он должен показать название страны и ее флаг в aonther деятельности .... я получить название страны, но не флаг в ImageView ....
Вот мой код:
public class AndroidJSONParsingActivity extends ListActivity {
// url to make request
private static String url = "http://*****@#[email protected]#$.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);
}
});
}
}
Vishesh чандра: У меня есть ошибка в этой строке ** Строка флага = ((ImageView) view.findViewById (R.id.flag)). getTag(). toString(); ** в моей ** AndroidJSONParsingActivity ** ... Любая идея ... –
что это за ошибка? –
** getTag() ** .... см. Приведенную выше строку ... изображение в строку и переход к следующему действию ... thats the error .. –