i am new to android,in my application i have a listview with image textview button and 3 checkboxes with values of 1,2,3.in run time i select the checkboxes based on my need, i want to add a filter for this listview for filtering the list based on the checkbox value,if i give 1 in searchbox the list should show the list of item that have the checkbox checked value of 1,if i give 2 the list should show the list of item that have the checkbox checked value of2 . can anyone please help me? below is my code
public class MainActivity extends ListActivity {
ListView lv;
Cursor cursor,cursor1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_contact);
cursor=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
startManagingCursor(cursor);
String[] from={ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone._ID};
int[] to={R.id.name_entry,R.id.number_entry};
ContactList listadapter=new ContactList(this,R.layout.single_row1,cursor,from,to);
setListAdapter(listadapter);
listadapter.notifyDataSetChanged();
lv=getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
class ContactList extends SimpleCursorAdapter implements Filterable {
private Context context;
String strfromMobileno="";
private int layout;
public ContactList(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
this.context=context;
this.layout=layout;
// TODO Auto-generated constructor stub
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
return v;
}
@Override
public void bindView(View v, final Context context, Cursor c) {
int nameCol = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String name = c.getString(nameCol);
int noCol = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String no = c.getString(noCol);
final CheckBox p1 = (CheckBox) v.findViewById(R.id.checkBox1);
final CheckBox p2 = (CheckBox) v.findViewById(R.id.checkBox2);
final CheckBox p3 = (CheckBox) v.findViewById(R.id.checkBox3);
final TextView name_text = (TextView) v.findViewById(R.id.name_entry);
if (name_text != null) {
name_text.setText(name);
}
final TextView no_text = (TextView) v.findViewById(R.id.number_entry);
if (no_text != null) {
no_text.setText(no);
}
final Button btn=(Button)v.findViewById(R.id.button1);
}
}
}
Aucun commentaire:
Enregistrer un commentaire