android - Show database details for item selected in spinner -
i using simplecursoradapter populate spinner name column database.
adapter:
spinneradapter = new simplecursoradapter( this, android.r.layout.simple_spinner_item, null, new string[] {supplierentry.column_supplier_name}, new int[] {android.r.id.text1}, 0); spinneradapter.setdropdownviewresource(android.r.layout.simple_spinner_item); msuppliersspinner.setadapter(spinneradapter); getloadermanager().initloader(suppliers_loader, null, this); cursor loader:
@override public loader<cursor> oncreateloader(int i, bundle bundle) { // define projection specifies columns table care about. string[] projection = { supplierentry._id, supplierentry.column_supplier_name}; // loader execute contentprovider's query method on background thread return new cursorloader(this, // parent activity context supplierentry.content_uri, // provider content uri query projection, // columns include in resulting cursor null, // no selection clause null, // no selection arguments null); // default sort order } how i, upon selecting item in spinner (the name column), show other details in textviews ?
first, set listener spinner callback when item selected.
msuppliersspinner.setonitemselectedlistener(this); i supply 'this' listener because fragment / activity implements interface, can write 1 between brackets well. can implement method:
@override public void onitemselected(adapterview<?> parent, view view, int position, long id) { //start cursorloader details } based on id, or position, know entry selected. @ point can start cursorloader (with selection details of particular entry). when callback in onloadfinished, can show details in textviews.
Comments
Post a Comment