/////here is my code///////////////////////
package my.com; import my.com.R; import my.com.SpinnerDBHelper; import android.app.Activity; import android.app.LauncherActivity.ListItem; import android.app.ListActivity; import android.content.Context; import android.database.Cursor; import android.os.Bundle; import android.text.Layout; import android.util.Log; import android.util.SparseBooleanArray; import android.view.View; import android.widget.Adapter; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Checkable; import android.widget.CursorAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.Toast; public class MyListActivity extends Activity { private String my_sel_items; ListView lView; String[] from; /** Called when the activity is first created. */ private SpinnerDBHelper thisTestDBAdapter; SimpleCursorAdapter adapter; public void onCreate(Bundle icicle) { super.onCreate(icicle); // setContentView(R.layout.main); setContentView(R.layout.main); my_sel_items=new String(); lView = (ListView) findViewById(R.id.listView1); thisTestDBAdapter = new SpinnerDBHelper(this); // View mlayout= findViewById(R.id.laidout); // set the color Button submit = (Button) findViewById(R.id.button); submit.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final SparseBooleanArray checkedItems = lView.getCheckedItemPositions(); if (checkedItems == null) { int duration = Toast.LENGTH_SHORT; Context context = getApplicationContext(); Toast toast = Toast.makeText(context, "no items selected", duration); toast.show(); return; } final int checkedItemsCount = checkedItems.size(); for (int i = 0; i < checkedItemsCount; ++i) { // This tells us the item position we are looking at final int position = checkedItems.keyAt(i); // And this tells us the item status at the above position final boolean isChecked = checkedItems.valueAt(i); // And we can get our data from the adapter like that Object currentItem =adapter.getItem(position); Context context = getApplicationContext(); //CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context,currentItem.toString() , duration); toast.show(); } } }); lView.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view2, int pos, long id) { // String valor2 = parent.getItemAtPosition(pos).toString(); // Toast.makeText(getBaseContext(),valor2,Toast.LENGTH_SHORT).show(); //Log.v("valor2:", valor2); // recProdSpinner(); final SparseBooleanArray checkedItems = lView.getCheckedItemPositions(); final int checkedItemsCount = checkedItems.size(); for (int i = 0; i < checkedItemsCount; ++i) { // This tells us the item position we are looking at final int position = checkedItems.keyAt(i); // And this tells us the item status at the above position final boolean isChecked = checkedItems.valueAt(i); // And we can get our data from the adapter like that final Object currentItem =adapter.getItem(position); // final Object c=adapter. Context context = getApplicationContext(); //CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context,currentItem.toString() , duration); toast.show(); } } }); Button cancel= (Button) findViewById(R.id.button2); thisTestDBAdapter.deleteAll(); thisTestDBAdapter.deleteAll(); thisTestDBAdapter.insertMedicine("Penadol","AA"); thisTestDBAdapter.insertMedicine("Calpol","AA"); thisTestDBAdapter.insertMedicine("Forage","AA"); thisTestDBAdapter.insertMedicine("Metlife","AA"); thisTestDBAdapter.insertMedicine("Memi","AA"); thisTestDBAdapter.insertMedicine("Demi","AA"); fillData(); // thisTestDBAdapter.insertPrescription(3,5,6); // thisTestDBAdapter.insertPrescription(2,5,6); // thisTestDBAdapter.insertPrescription(4,5,6); // thisTestDBAdapter.insertPrescription(1,5,6); // Create an array of Strings, that will be put to our ListActivity //String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse", // }; //setListAdapter(new ArrayAdapter<String>(this, //android.R.layout.simple_list_item_multiple_choice, //android.R.id.text1, names)); //ListView listView = getListView(); //listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } private void fillData() { Cursor coloursCursor; //Spinner colourSpinner = (Spinner) findViewById(R.id.my_colour_spinner); coloursCursor = thisTestDBAdapter.fetchAllMedicines(); startManagingCursor( coloursCursor); /*Create an array to specify the fields we want to display in the list (only the 'colourName' column in this case) */ from = new String[]{thisTestDBAdapter.medicine_name}; /* and an array of the fields we want to bind those fields to (in this case just the textView 'tvDBViewRow' from our new db_view_row.xml layout above) */ int[] to = new int[]{android.R.id.text1, android.R.id.text2}; /* Now create a simple cursor adapter.. */ //ListAdapter adapter; //setListAdapter(new ArrayAdapter<String>(this, //android.R.layout.simple_list_item_multiple_choice, //android.R.id.text1, from)); //CursorAdapter colourAdapter = //new SimpleCursorAdapter(this, R.layout.main, coloursCursor, from, to); // setListAdapter(colourAdapter); // ListAdapter adapter = new SimpleCursorAdapter(this, // Context. // android.R.layout.select_dialog_multichoice, // Specify the row template // // to use (here, two // // columns bound to the // // two retrieved cursor // // rows). // coloursCursor, // Pass in the cursor to bind to. // // Array of cursor columns to bind to. // from, // // Parallel array of which template objects to bind to those // // columns // to); adapter=new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, coloursCursor, from ,to); // lView.setAdapter(adapter); lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); lView.setItemsCanFocus(true); lView.setClickable(true); lView.setFocusable(true); // lView.setBackgroundResource(android.R.drawable.menuitem_background); final SparseBooleanArray checkedItems = lView.getCheckedItemPositions(); if (checkedItems == null) { // That means our list is not able to handle selection // (choiceMode is CHOICE_MODE_NONE for example) return; } final int checkedItemsCount = checkedItems.size(); for (int i = 0; i < checkedItemsCount; ++i) { // This tells us the item position we are looking at final int position = checkedItems.keyAt(i); // And this tells us the item status at the above position final boolean isChecked = checkedItems.valueAt(i); // And we can get our data from the adapter like that ListItem currentItem =(ListItem) adapter.getItem(position); Context context = getApplicationContext(); //CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context," "+currentItem, duration); toast.show(); } // Bind to our new adapter. // setListAdapter(adapter); // ListView listView = getListView(); // listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); /* and assign it to our Spinner widget */ //colourSpinner.setAdapter(colourAdapter); } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en