Pramod, you are creating new ArrayList that backs new SimpleAdapter every time you receive an update, hence all there is to display is only what came with the update. Activity should have one Adapter per ListView and both of those should not be re-created, but created once and the updated, when needed.
Your ListView and Adapter are used wrongly. Please read tutorials on both of those. On Wed, May 25, 2011 at 9:46 AM, pramod.deore <[email protected]> wrote: > Yes Daniel I will try some sample code side by side but it will be > great if you help to solve this tragidy. Look at my code: > > private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() > { > @Override > public void onReceive(Context context, Intent intent) > { > String res = intent.getStringExtra("Response"); > System.out.println ("***********************************"); > System.out.println (res); > > if (res.length() == 0) > { > //Response has not changed > System.out.println("value is null................."); > } > > else > { > String delims = "\\^"; > > tokens = res.split(delims); > > for (int i=0;i<tokens.length;i++) > { > System.out.println("At "+i+" Value is "+tokens[i]); > } > > if (tokens[1].equalsIgnoreCase("1")) > > { > > //write code for empId is exist already or not? If > exist then > update row else create new row > showList(); > > } > > else > { > //Don't this record to listview > } > } > > } > }; > > > > > public void showList() > { > > ArrayList<HashMap<String, String>> mylist = new > ArrayList<HashMap<String, String>>(); > HashMap<String, String> map = new HashMap<String, > String>(); > map.put("EmpId", tokens[2]); > map.put("Name", tokens[4]); > map.put("MobNo", tokens[5]); > > mylist.add(map); > // ... > SimpleAdapter mSchedule = new SimpleAdapter(this, > mylist, > R.layout.listcolumns, > new String[] {"EmpId", "Name", "MobNo"}, > new int[] > {R.id.EmpId, R.id.Name, R.id.MobNo}); > list.setAdapter(mSchedule); > } > > > > > > Now using this code listview updated continously but it shows only one > updated record. Means suppose first record is like: > > EmpId EmpName MobNo City ..... Gender > > > 1 Pramod 789 Nasik M > > and suppose server send second record then first record is gone and > shows only one record as: > > > > EmpId EmpName MobNo City ..... Gender > > 1 1 Tom 456 NY M > > > > > On May 25, 1:29 pm, Daniel Drozdzewski <[email protected]> > wrote: >> Pramod, >> >> You have to read up on ListView and some Adapter that backs the >> ListView providing it with data. >> >> When you receive new set of data to be displayed or your data has >> changed, you call BaseAdapter.notifyDataSetChanged() to notify the >> associated ListView to redraw all visible items. >> >> ListView and Adapter are powerful, hence not easy to grasp at the >> beginning, so you have to go through some tutorial first, if you want >> to use them. >> >> >> >> >> >> On Wed, May 25, 2011 at 9:18 AM, pramod.deore <[email protected]> >> wrote: >> > Hi actually I am getting a string with some delimilater. Now using >> > split() I am split that response. after spliting I am getting string >> > array of size 40. I am not going to display all 40 fields. I will show >> > near about 10 fields. >> >> > Once again let me explain what I want: >> >> > Using socket connection I am receiving response from server. I want to >> > display this response in list. This list contains say 10 columns. >> > Suppose first two records as >> >> > EmpId EmpName MobNo City ..... Gender >> >> > 1 Pramod 789 Nasik M >> > 1 1 Tom 456 NY M >> >> > Now suppose next record again for EmpId 1 then other fields will >> > change and it will be: >> >> > EmpId EmpName MobNo City ..... Gender >> >> > 1 Deore 789 Nasik M >> > 1 1 Tom 456 NY M >> >> > Now suppose server send again some data with EmpId which is not exist >> > above then it must have to add this new record.And it will be >> >> > EmpId EmpName MobNo City ..... Gender >> >> > 1 Deore 789 Nasik M >> > 1 1 Tom 456 NY M >> > 45 Rob 123 XYZ M >> >> > Now how to achieve this? >> >> > On May 25, 12:33 pm, Nikolay Elenkov <[email protected]> >> > wrote: >> >> On Wed, May 25, 2011 at 4:15 PM, pramod.deore <[email protected]> >> >> wrote: >> >> >> > On May 25, 12:08 pm, Nikolay Elenkov <[email protected]> >> >> > wrote: >> >> >> On Wed, May 25, 2011 at 4:01 PM, pramod.deore >> >> >> <[email protected]> wrote: >> >> >> > Hi Ravi thanks for reply. actually it will becomes more complicated. >> >> >> > Because server is sending data 2-3 times within a second And it will >> >> >> > not be good idea to store data such a frequently. >> >> >> >> > Can somebody please provide me a guideline How I can check whether >> >> >> > some key (here Name ) is already exist in listview? >> >> >> >> If you don't have much data to deal with it, it might be easier to >> >> >> just replace everything and re-display. It doesn't really matter >> >> >> what exactly changed. >> >> >> > Actually I am dealing with huge data. In above code just show a sample >> >> > of three fields but there are more than 40 fields. >> >> >> Why is top-posting the norm on this list? Please write your reply *below* >> >> the previous one, so it reads like a conversation. Trimming also helps. >> >> >> How are you going to display 40 fields in a ListView? It doesn't really >> >> matter >> >> though, you usually care if a particular row/record changed and >> >> update/replace >> >> the whole record in your model/adapter. If you want to be able replace a >> >> particular record, use some key (e.g., the employee ID) to search for it, >> >> and update/replace it.- Hide quoted text - >> >> >> - Show quoted text - >> >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Android Developers" group. >> > To post to this group, send email to [email protected] >> > To unsubscribe from this group, send email to >> > [email protected] >> > For more options, visit this group at >> >http://groups.google.com/group/android-developers?hl=en >> >> -- >> Daniel Drozdzewski- Hide quoted text - >> >> - Show quoted text - > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Daniel Drozdzewski -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

