lundi 5 octobre 2015

Delete checked item from list view and data from database, using adapter class

 public class delete extends BaseAdapter {
  SQLiteDatabase db;

String am;


 private final Context c;
private final ArrayList<String> str;
 private final String[] number;


ArrayList<Integer> checks=new ArrayList<Integer>();

public delete(Context c, ArrayList<String> str, String[] number, ArrayList<Integer> checks) {
    this.c = c;

    this.str = str;


    this.number = number;
    this.checks=checks;
}




@Override
public int getCount() {

    return str.size();


}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater= (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View ListView ;


    if(convertView==null)
    {
        ListView=new View(c);
        ListView=inflater.inflate(R.layout.button,null);

        TextView textview=(TextView) ListView.findViewById(R.id.textView6);
        textview.setText(str.get(position));



    }

    else
    {
        ListView=(View)convertView;
    }

    Button btnupdate=(Button)ListView.findViewById(R.id.button4);



      //checkbox declaration  
    CheckBox chk=(CheckBox)ListView.findViewById(R.id.chk1);




btnupdate.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
      db=c.openOrCreateDatabase("Student",Context.MODE_PRIVATE, null);
      String num = number[position];
      Cursor cc=db.rawQuery("select mobile from detail where mobile='"+num+"'", null);

      if (cc.moveToFirst()) {
          do {


               am = cc.getString(cc.getColumnIndex("mobile"));




             } while (cc.moveToNext());

      }



      Intent i=new Intent(c,Update.class);

      i.putExtra("value",am);
      c.startActivity(i);

  }



});













    return ListView;
  }



    }

//It show all the data in list view with update button and check box in list view. There is delete button which is suppose to delete all the item which is checked. //Delete button is on main activity where list view is added.

Aucun commentaire:

Enregistrer un commentaire