im писать приложение, которое должно получить некоторый json из моей БД, я получаю данные, но теперь я пытаюсь также просмотреть значок рядом с информацией, которая показана в списке.
Линия, которая создает проблемы:
mChart.setTag(URL);
new DownloadImagesTask.execute(mChart); <------
MainActivity:
public class MainActivity extends Activity {
ListView list;
TextView icon;
TextView name;
TextView developer;
TextView size;
Button Btngetdata;
ArrayList<HashMap<String, String>> mList = new ArrayList<HashMap<String, String>>();
private static String url = "http://appwhittle.com/getdata.php";
private static final String TAG_ITEM = "app_item";
private static final String TAG_ICON = "app_icon";
private static final String TAG_NAME = "app_name";
private static final String TAG_DEVELOPER = "app_developer";
private static final String TAG_SIZE = "app_size";
JSONArray mJsonArray = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mList = new ArrayList<HashMap<String, String>>();
new JSONParse().execute();
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
icon = (TextView)findViewById(R.id.icon);
name = (TextView)findViewById(R.id.name);
size = (TextView)findViewById(R.id.size);
developer = (TextView)findViewById(R.id.developer);
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl(url);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
mJsonArray = json.getJSONArray(TAG_ITEM);
for(int i = 0; i < mJsonArray.length(); i++){
JSONObject c = mJsonArray.getJSONObject(i);
String name = c.getString(TAG_NAME);
String size = c.getString(TAG_SIZE);
String developer = c.getString(TAG_DEVELOPER);
String icon = c.getString(TAG_ICON);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ICON, icon);
map.put(TAG_NAME, name);
map.put(TAG_DEVELOPER, "Developer: " + developer);
map.put(TAG_SIZE, size + " MB");
mList.add(map);
list=(ListView)findViewById(R.id.list);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, mList,
R.layout.list_v,
new String[] {TAG_NAME, TAG_DEVELOPER, TAG_SIZE }, new int[] {
R.id.name, R.id.developer, R.id.size});
ImageView mChart = (ImageView) findViewById(R.id.icon);
String URL = "http://www...anything ...";
mChart.setTag(URL);
new DownloadImagesTask.execute(mChart);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at "+ mList.get(+position).get(TAG_NAME), Toast.LENGTH_SHORT).show();
}
});
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
DownloadImagesTask:
public class DownloadImagesTask extends AsyncTask<ImageView, Void, Bitmap> {
ImageView imageView = null;
@Override
protected Bitmap doInBackground(ImageView... imageViews) {
this.imageView = imageViews[0];
return download_Image((String)imageView.getTag());
}
@Override
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
private Bitmap download_Image(String url) {
return null;
}
}
Любая помощь очень ценится! Спасибо заранее!