Note that there are some explanatory texts on larger screens.

plurals
  1. POonly Last Row is being Updated BY chaning data set value in CustomListView
    text
    copied!<p>In the above piece of code i`m trying to update Imageresource in customListview using simpleadapter here the problem is whenever i Notifychngedataset() it update only Last row </p> <pre><code> public class HelloWorldActivity extends Activity { private ArrayList &lt;HashMap&lt;String, Object&gt;&gt; my; ArrayList&lt;String&gt; ImageList; /** Variable Declaration For Items Parsed from TwiterJson*/ private final String TEXT="text"; private final String USER="user"; private final String IMAGEURL="imageurl"; private final String URL="url"; private ListView listView; ArrayList&lt;String&gt; textItems; ArrayList&lt;String&gt; userlist; ArrayList&lt;String&gt; urllist; HashMap&lt;String, Object&gt; hm; String line; private String TAG="HelloWorldActivity"; private ProgressBar mProgressBar; View view; Simpleadapter adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(R.id.list); mProgressBar=(ProgressBar)findViewById(R.id.progressbar); // Call the Asynch Activity new AsynchTask().execute(); } /** SimpleAdapater Class Definition*/ public class Simpleadapter extends SimpleAdapter { public Simpleadapter(Context context, List&lt;? extends Map&lt;String, ?&gt;&gt; data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); } @Override public View getView(int position, View convertView, ViewGroup parent) { view = super.getView(position, convertView, parent); final Button mButton=(Button)view.findViewById(R.id.gobutton); final ImageView mImageview=(ImageView) view.findViewById(R.id.image1); mImageview.setImageBitmap((Bitmap) my.get(position).get(IMAGEURL)); final int num=position; mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((String) my.get(num).get(URL)))); } }); return view; } } /**Inner Class for Background Task*/ private class AsynchTask extends AsyncTask&lt;Void, Integer, Void&gt; { URLConnection tc; BufferedReader in; URL twitter; int num=0; @Override protected void onPreExecute() { super.onPreExecute(); try { mProgressBar.setVisibility(View.VISIBLE); } catch (Exception e) { Log.e(TAG,""+e.getMessage()); } } @Override protected Void doInBackground(Void... params) { try{ twitter = new URL("http://twitter.com/statuses/public_timeline.json"); tc = twitter.openConnection(); my = new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;(); ImageList=new ArrayList&lt;String&gt;(); in = new BufferedReader(new InputStreamReader( tc.getInputStream())); while ((line = in.readLine()) != null) { JSONArray ja = new JSONArray(line); Log.e("Length",""+ja.length()); for (int i = 0; i &lt; ja.length(); i++) { JSONObject jo = (JSONObject) ja.get(i); /**Data Insert into the HashMap Object*/ hm=new HashMap&lt;String, Object&gt;(); hm.put(TEXT,jo.getString("text")); hm.put(USER,jo.getJSONObject("user").getString("name")); hm.put(URL,"http://twitter.com/#!/"+jo.getJSONObject("user").getString("screen_name")); hm.put(IMAGEURL, BitmapFactory.decodeResource(HelloWorldActivity.this.getResources(), R.drawable.icon)); ImageList.add(jo.getJSONObject("user").getString("profile_image_url")); my.add(hm); } } } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); mProgressBar.setProgress(0); mProgressBar.setVisibility(View.GONE); adapter= new Simpleadapter(HelloWorldActivity.this, my, R.layout.listcontent, new String[]{TEXT,USER}, new int[]{R.id.text2,R.id.text1}); listView.setAdapter(adapter); new AsynchTaskForImageLoading().execute(); } } /**Method to convert Url to the Bitmap*/ private Bitmap getDrawable_from_url(String url) { try{ Bitmap x; HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection(); connection.setRequestProperty("User-agent","Mozilla/4.0"); connection.connect(); InputStream input = connection.getInputStream(); x = BitmapFactory.decodeStream(input); return x; } catch (Exception e) { Log.e(TAG,""+e.getMessage()); return null; } } private class AsynchTaskForImageLoading extends AsyncTask&lt;Void, Bitmap,Void&gt; { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBackground(Void... params) { for(int i=0;i&lt;ImageList.size();i++){ publishProgress(getDrawable_from_url(ImageList.get(i))); } return null; } @Override protected void onProgressUpdate(Bitmap... values) { super.onProgressUpdate(values); for (Bitmap value : values) { hm.put(IMAGEURL,value); adapter.notifyDataSetChanged(); } } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); } } </code></pre> <p>` }// End of Main Activity Class</p> <p>i want to update each row`s Imageview but somehow it is updating only Last row of my Listview Recursively i can the changes that is changing images frequently of the last row...</p> <p>Thanks in Adnavce</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload