How to add newly added listitems from Top. sql server

Viewed 25

I want add newly added listitems from the index 0. like if one items is present already then if i insert another item so i want it display at top.

  ListView lst1 = (ListView) findViewById(R.id.list2);
     List<Map<String, String>> MyDataList = null;
     reuestitems myData = new reuestitems();
     MyDataList = myData.getlist10();
     String[] from = {"bloodgrp", "date", "time", "name", "Username"};
     int[] to = {R.id.listt, R.id.date, R.id.time1, R.id.name3, R.id.user};
     ad = new SimpleAdapter(request.this, MyDataList, R.layout.listrequest, from, to);
     lst1.setAdapter(ad);

       lst1.setBackgroundColor(getColor(R.color.colorPrimary));
     if(ad.getCount()==0){
         Toast.makeText(getApplicationContext(), "No requests are currently visible", Toast.LENGTH_SHORT).show();
     }
1 Answers

i strongly suggest to use RecyclerView instead of ListView. the function you are looking for is adapter.notifyItemInserted or if you want to remove an item adapter.notifyItemRemoved.

Related