title: Android: How to clear all items in a custom listview
body: <p>I know the normal listview can be cleared by calling 'clear' to arrayadapter etc. But how we do clear items if it is a custom listview ??</p>
  
  <p>Here is my code :</p>
  
  <p>Activity:</p>
  
  <pre><code>public class GroupList extends Activity{
      TextView v_no_groups;
      Cursor grouplist_cur;
      Context context = GroupList.this;
      SQLiteDatabase mydb=null;
      ListView v_grouplist;
      ArrayList&lt;String&gt; grpname_arr = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; grpid_arr = new ArrayList&lt;String&gt;();
      ArrayList&lt;Integer&gt; memcount_arr = new ArrayList&lt;Integer&gt;();
      ArrayList&lt;Integer&gt; totaltrans_arr = new ArrayList&lt;Integer&gt;();
      M_grplist_adapter mga;
      Button v_creategrp;
      List&lt;M_grplist_class&gt; glist;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.grouplist);
      }
  
      @Override
      protected void onResume() {
  
          super.onResume();
  
          //mga.clearlistview();
  
          v_creategrp = (Button)findViewById(R.id.x_creategrp);
          v_grouplist = (ListView)findViewById(android.R.id.list);
          registerForContextMenu(v_grouplist);
          v_no_groups = (TextView)findViewById(R.id.x_no_groups);
  
          mydb = this.openOrCreateDatabase("moneydb", 0, null);
          mydb.execSQL("CREATE TABLE IF NOT EXISTS grouptable(grpname varchar(30),grpid varchar(10),memcount number(3),totaltrans number(3))");   
          grouplist_cur = mydb.rawQuery("SELECT * from grouptable", null);
  
          if(grouplist_cur.getCount()&gt;0)
          {
  
              grouplist_cur.moveToFirst();
              do{
                  grpname_arr.add(grouplist_cur.getString(0));
                  memcount_arr.add(grouplist_cur.getInt(2));
                  totaltrans_arr.add(grouplist_cur.getInt(3));
              }while(grouplist_cur.moveToNext());
  
              glist = new ArrayList&lt;M_grplist_class&gt;();
              for(int i=grpname_arr.size()-1;i&gt;=0;i--){
                  glist.add(new M_grplist_class(grpname_arr.get(i),memcount_arr.get(i),totaltrans_arr.get(i)));
              }
  
              mga = new M_grplist_adapter(context,glist);
              v_grouplist.setAdapter(mga);
  
              grouplist_cur.close();
              mydb.close();
          }
          else
          {
              grouplist_cur.close();
              mydb.close();
          }
  
          v_creategrp.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                  Intent int_newgrp = new Intent(context,NewGroup.class);
                  startActivity(int_newgrp);
              }
          });
      }
  </code></pre>
  
  <p>grplist_adapter class:</p>
  
  <pre><code>public class M_grplist_adapter extends BaseAdapter{
      private List&lt;M_grplist_class&gt; items = null;
      private Context context;
      private int index;
  
      public M_grplist_adapter(Context context,List&lt;M_grplist_class&gt; items){
          items.clear();
          notifyDataSetChanged();
          this.items = items;
          this.context = context;
          //notifyDataSetChanged();
          Log.i("Dillu", "you are here M_grplist_adapter");
      }
  
      @Override
      public int getCount() {
          Log.i("Dillu", "you are here getcount");
          return items.size();
  
      }
  
      @Override
      public Object getItem(int position) {
          index = position;
          Log.i("Dillu", "you are here getitem");
          return items.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          Log.i("Dillu", "you are here getitemid");
          return position;
      }
  
      public String clear()
      {
          String name = items.get(index).getgrpname();
          items.remove(index);
          notifyDataSetChanged();
          return name;
      }
  
      @Override
      public View getView(int index, View convertView, ViewGroup parent) {
          Log.i("Dillu", "you are here getview");
          LinearLayout rowLayout=null;
          if(convertView==null) 
              rowLayout = (LinearLayout)LayoutInflater.from(context).inflate(R.layout.m_grplist_item,parent,false);
          else
              rowLayout = (LinearLayout)convertView;  
  
          TextView gname = (TextView)rowLayout.findViewById(R.id.grpname);
          gname.setText(items.get(index).getgrpname());
  
          TextView gmems = (TextView)rowLayout.findViewById(R.id.noofmems);
          int int_temp = items.get(index).getmemcount();
          String str_temp = Integer.toString(int_temp);
          gmems.setText(str_temp);
  
          TextView gtrans = (TextView)rowLayout.findViewById(R.id.nooftrans);
          int int_temp_1 = items.get(index).gettotaltrans();
          String str_temp_1 = Integer.toString(int_temp_1);
          gtrans.setText(str_temp_1);
  
          return rowLayout;
      }
  
  }
  </code></pre>
  
  <p>M_grplist_class :</p>
  
  <pre><code>public class M_grplist_class {
      String loc_grpname;
      int loc_memcount;
      int loc_totaltrans;
  
       public M_grplist_class(String grpname,int memcount,int totaltrans){
           loc_grpname = grpname;
           loc_memcount = memcount;
           loc_totaltrans = totaltrans; 
       }
  
       public String getgrpname(){
           return loc_grpname;
       }
  
       public int getmemcount(){
           return loc_memcount;
       }
  
       public int gettotaltrans(){
           return loc_totaltrans;
       }
  
  }
  </code></pre>
  
  <p>Please provide a solution for this.</p>