Thanks Bibek for reply,

I have following code

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        System.out.println ("Inside onCreate method of ShowStatus");
        anim = AnimationUtils.loadAnimation( this, R.anim.magnify );
        try
        {
                sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
MODE_PRIVATE, null);

                Cursor c = sampleDB.rawQuery ("SELECT * FROM SwitchTable
ORDER BY RoomID",null);

                int count = c.getCount();
                System.out.println ("Total number of records are"+count);
                if (c != null )
                {
                        if  (c.moveToFirst())
                        {
                                do
                                {
                                        rid = 
c.getInt(c.getColumnIndex("RoomID"));
                                        sid = 
c.getInt(c.getColumnIndex("SwitchID"));

                                        roomName = 
c.getString(c.getColumnIndex("RoomName"));
                                        switchName = 
c.getString(c.getColumnIndex("SwitchName"));


                                        System.out.println 
(rid+":"+roomName+":"+sid
+":"+switchName);
                                        results.add( 
rid+":"+roomName+"?"+sid+","+switchName);
                                        results1.add( roomName+"-"+switchName);

                                }
                                while (c.moveToNext());
                                c.close();
                        }
                }

                this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,results1));

        }
        catch (SQLiteException se )
        {
                Log.e(getClass().getSimpleName(), "Could not create or Open
the database");
        }
        finally
        {
                        sampleDB.close();
        }
        registerForContextMenu(getListView());

    }

        public void onCreateContextMenu(ContextMenu menu, View
v,ContextMenuInfo menuInfo)
        {

                    info = (AdapterView.AdapterContextMenuInfo) menuInfo;

                long id = getListAdapter().getItemId(info.position);
                Object obj = getListAdapter().getItem((int) id);
                String ss = obj.toString();

                newRoomName = ss.substring(0,ss.indexOf("-"));
                newSwitchName = ss.substring(ss.indexOf("-")+1);

//MY PROBLEM IS THAT in list I had passes results1 and it  has only 2
param RoomName and SwitchName. But what I want is - I want to pass
result (insted of result1)  so I can get roomID also.

                for (int i=0;i<menuItems.length;i++)
                {
                          System.out.println (menuItems[i]);
                }

                System.out.println ("************************");
                for (int i = 0; i<menuItems.length; i++)
                {
                          menu.add(Menu.NONE, i, i, menuItems[i]);
                }
        }

        public boolean onContextItemSelected(MenuItem item)
        {
                AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
                int menuItemIndex = item.getItemId();

                String menuItemName = menuItems[menuItemIndex];
                System.out.println ("&&&"+menuItemName);

                if (menuItemName.equalsIgnoreCase("Add Switch"))
                {
                        System.out.println ("Inside Add Switch");
                        this.setListAdapter(new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
switchArray));
                        //write a method that will check whether user click on 
other item
or not.


                }

                return true;
        }

        protected void onListItemClick(ListView l,View v,int position,long
id)
        {

                v.startAnimation( anim );
                super.onListItemClick(l, v, position, id);
                System.out.println ("User click on switch list");
                System.out.println ("###"+newRoomName);
                System.out.println ("%%%"+newSwitchName);
                newRoomId = calculateNewRoomID(newRoomName,newSwitchName);
                System.out.println ("Now rid is"+newRoomId);
        }



On Nov 25, 2:15 pm, Kumar Bibek <[email protected]> wrote:
> Not sure about your exact requirement, but I guess Expandable list View
> could be of help......
>
> Kumar Bibekhttp://techdroid.kbeanie.comhttp://www.kbeanie.com
>
> On Thu, Nov 25, 2010 at 2:42 PM, pramod.deore <[email protected]>wrote:
>
>
>
> > is there is any way using that I can hide some part of list.
> > If suppose my list is like
>
> > 1:Hall:1:AC
> > 1:Hall:2:TV
> > 1:Hall:3:Tube
>
> > But I want to show list as
> > Hall:Ac
> > Hall:TV
> > Hall:Tube.
>
> > On Nov 25, 1:21 pm, "pramod.deore" <[email protected]> wrote:
> > > Hi all,
>
> > > I have a 2 ArrayList as
>
> > > ArrayList<String> results = new ArrayList<String>();
> > > ArrayList<String> results1 = new ArrayList<String>();
>
> > > From database I retrieved  data  and display them in the form of list.
>
> > > results.add( rid+":"+roomName+"?"+sid+","+switchName);
> > > results1.add( roomName+"-"+switchName);
>
> > > this.setListAdapter(new ArrayAdapter<String>(this,
> > > android.R.layout.simple_list_item_1,results));
>
> > > Firstly I have only one ArrayList (i.e results). But in the list I
> > > don't want to show rid,sid.(i.e roomid and switchid). Therefore  I had
> > > created second arrayList (i.e results) and use it in seListAdapter as
>
> > > this.setListAdapter(new ArrayAdapter<String>(this,
> > > android.R.layout.simple_list_item_1,results1));
>
> > > Now on list it only shows RoomName and SwitchName. Upto now everything
> > > is ok.
>
> > > But I had used ContextMenu on this list.I had override the
>
> > > public void onCreateContextMenu(ContextMenu menu, View
> > > v,ContextMenuInfo menuInfo)
> > > {
> > > //here I had given 3 options 1. Add Switch 2. RemoveSwitch 3. Back
>
> > > }
>
> > > public boolean onContextItemSelected(MenuItem item)
> > > {
> > >   //But now I am getting only 2 values which are in the results1 (i.e
> > > RoomName and SwitchName). But also I want RoomID and SwitchID. I don't
> > > know how to get them?
> > > I had tried using
> > > Iterator itr = results.iterator();
> > >                 while(itr.hasNext())
> > >                 {
> > >                  String ss = itr.next().toString();
>
> > >                 String rID1 = ss.substring(0,ss.indexOf(":"));
> > >                 rID = Integer.parseInt(rID1);
> > > .....................
>
> > >                 }
> > >        // But the problem is that it returns only last record. (i.e.
> > > last rid, sid).
>
> > > }
>
> > > Now my problem is that how to get rid and sid.
>
> > --
> > 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]<android-developers%[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
>

-- 
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