Resolveuri Failed On Bad Bitmap In Listview From Json
Solution 1:
The problem here is you are setting a url
(Which is of String type) directly to the imageview
and requesting the SimpleAdapter
to bind it to the imageview
. I would suggest you to use other adapters as in my below code. Because SimpleAdapter
and SimpleCursorAdapter
are mostly used when you have data in the local(sqlite) database
to make the content reflected directly on the listview
. But here you get the data from the server. So here you go with it.
publicclassCustomListAdapterextendsBaseAdapter {
privateActivity activity;
privateArrayList<HashMap<String, String>> data;
privatestaticLayoutInflater inflater=null;
publicImageLoader imageLoader;
publicCustomListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=newImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
publicObjectgetItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
publicViewgetView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null); //This should be your row layoutTextView titleTextView = (TextView)vi.findViewById(R.id.title); // titleImageView thumb_image=(ImageView)vi.findViewById(R.id.imageview1); //imageHashMap<String, String> localhash = newHashMap<String, String>();
localhash = data.get(position);
String currenttitle = localhash.get("title");
String imagepath = localhash.get("imagen");
titleTextView.setText(currenttitle);
if(!imagepath.equals(""))
{
imageLoader.DisplayImage(imagepath , thumb_image);
}
return vi;
}
}
You set the above adapter to your listview
in the below way. Include the below code after you load the data from the network. To load the data from the server, make sure you don't run the network operations on UI thread. For this you can make use of AsyncTask,Handlers, Service etc., If you use AsyncTask, include the below lines in onPostExecute()
.
CustomListAdapteradapter=newCustomListAdapter(YourActivity.this, dataArrayList);
listView.setAdapter(adapter);
Hope this helps and btw sorry for the delay in answering.
Post a Comment for "Resolveuri Failed On Bad Bitmap In Listview From Json"