1)Context Menu is not getting item required
OR
2)onclick should work
public class HomeActivity extends Activity {
        private static final int Id_Details = 0;
        private static final int Id_Email = 1;
        /**
         * @see android.app.Activity#onCreate(Bundle)
         */
        private final int MENU_ITEM_0 = 0;
        private final int MENU_ITEM_1 = 1;
        SQLiteDatabase db;
        protected Cursor cursor;
        public ListAdapter adapter;
        ListViewAdapter lviewAdapter;
        ListView HomeActivity;
        protected Object s ;
        TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                // TODO Put your code here
                setContentView(R.layout.main);
                init();
             //getting writable db and display
                                db = (new
HomeActivitySqlOpenHelper(this)).getWritableDatabase();
                                HomeActivity = (ListView)
findViewById(R.id.list);
                                cursor= db.rawQuery("SELECT _id, name,
date FROM table1", null);
                                adapter = new
SimpleCursorAdapter(HomeActivity.this,R.layout.list_item,cursor,new
String[] {"name", "date"},new int[] {R.id.name, R.id.date});
                                HomeActivity.setAdapter(adapter);
                                HomeActivity.setClickable(true);
                //for context menu
                                registerForContextMenu(HomeActivity);
        }
        /*
        public void onItemClick(AdapterView<?> a, View v, int
position, long
id) {
                // TODO Auto-generated method stub
                AlertDialog.Builder adb=new
AlertDialog.Builder(HomeActivity.this);
                adb.setTitle("ItemClicked");
                adb.setMessage("Selected Item is =
"+HomeActivity.getItemAtPosition(position).toString());
                adb.setPositiveButton("Ok", null);
                adb.show();
        }
*/
        public void onCreateContextMenu(ContextMenu menu,View
v,ContextMenuInfo menuInfo)
            {
                        AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo)menuInfo;
                        //tv = (TextView)
v.findViewById(info.position);
                        //CharSequence itemTitle = tv.getText();
                        //      ListView lv= (ListView)
HomeActivity.getItemAtPosition(info.position);
                        //
tv.setText(HomeActivity.getAdapter().getItem(info.position).toString());
                  //  String keyword = o.toString();
                        //menu.setHeaderTitle(tv.getText());
                menu.add(0, Id_Details, 0, "Details");
                        menu.add(0, Id_Email, 0, "Email");
                        //    menu.add((CharSequence)
HomeActivity.getItemAtPosition(info.position));
                        //  Toast.makeText(HomeActivity.this,
(CharSequence) s ,
Toast.LENGTH_SHORT).show();
            }
        public boolean onContextItemSelected(MenuItem item)
            {
                //return true;
                        switch (item.getItemId()) {
                                        case  Id_Details :
                                                        break;
                                        case  Id_Email :
                                                        //
AndroidManifest.xml must have the following permission:
                                                        // <uses-
permission android:name="android.permission.INTERNET"/

                                                        Intent
emailIntent = new
Intent(android.content.Intent.ACTION_SEND);
 
emailIntent.setType("plain/text");
 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new
String[]{"[email protected]"});
 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Birthday!");
 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Happy
Birthady!");
 
startActivity(Intent.createChooser(emailIntent, "Send
mail..."));
                                                        break;
                                        default:
                                                        break;
        }
             //HomeActivity.setText(item.getTitle());
             return true;
            }
        public void LoadDataToScreen()
        {
                        // TODO Auto-generated method stub
                                        cursor= db.rawQuery("SELECT
_id, name, date FROM table1", null);
                                        adapter = new
SimpleCursorAdapter(HomeActivity.this,R.layout.list_item,cursor,new
String[] {"name", "date"},new int[] {R.id.name, R.id.date});
 
HomeActivity.setAdapter(adapter);
        }
        public boolean onCreateOptionsMenu(Menu menu)
        {
                                        menu.add(0, MENU_ITEM_0, 0,
"ADD");
                                        menu.add(0, MENU_ITEM_1, 0,
"ABOUT");
                                        return true;
        }
        public boolean onOptionsItemSelected(MenuItem item)
        {
                                        switch (item.getItemId()) {
                                                        case
MENU_ITEM_0:
                                                                                
//
put your code here
 
Toast.makeText(this, "Add birthday!!",
Toast.LENGTH_SHORT).show();
 
Intent MyIntent = new
Intent(HomeActivity.this,AddBirthday.class);
 
HomeActivity.this.startActivity(MyIntent);
 
break;
                                                        case
MENU_ITEM_1:
                                                                                
//
put your code here
 
Toast.makeText(this, "About birthady!!",
Toast.LENGTH_SHORT).show();
 
break;
                                                        default:
                                                                                
//
put your code here
        }
            return false;
        }
        private void init()
        {
                                                        // TODO Auto-
generated method stub
                                                        SQLiteDatabase
db =openOrCreateDatabase("info.db",
MODE_PRIVATE, null);
 
db.execSQL("CREATE TABLE IF NOT EXISTS table1 (_id INTEGER
PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL,date TEXT NOT NULL,email
TEXT UNIQUE NOT NULL);");
 
Toast.makeText(this, "Db is open now",
Toast.LENGTH_SHORT).show();
        }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to