Here is my .java file
public class SwitchSetting extends Activity implements OnClickListener
{
        EventDataSQLHelper eventsData;
        TextView output;
        StringBuilder ret;
        private static final int ADD_ROOM = 0;
        private static final int MAIN_HALL = Menu.FIRST;
        private static final int BEDROOM = MAIN_HALL + 1;
        private static final int KITCHEN = BEDROOM + 1;
        private static final int BATHROOM = KITCHEN + 1;


        public void onCreate(Bundle savedInstanceState)
    {
                System.out.println ("Inside onCreate");
        super.onCreate(savedInstanceState);

        eventsData = new EventDataSQLHelper(this);
        Cursor cursor = getEvents();
            showEvents(cursor);

            setContentView(R.layout.text);
            output = (TextView) findViewById(R.id.text);
            output.setText(ret);


    }



        public boolean onCreateOptionsMenu(Menu menu)
        {
                super.onCreateOptionsMenu(menu);
                SubMenu addMenu = menu.addSubMenu("Add Room");
                SubMenu quiteMenu = menu.addSubMenu("Quite");
                addMenu.add(ADD_ROOM,MAIN_HALL,0,"Main Hall");
                addMenu.add(ADD_ROOM,BEDROOM,0,"Bedroom");
                addMenu.add(ADD_ROOM,KITCHEN,0,"Kitchen");
                addMenu.add(ADD_ROOM,BATHROOM,0,"Bathroom");

                eventsData = new EventDataSQLHelper(this);
                 //addEvent("Room id");

                return true;
        }

        public boolean onOptionsItemSelected(MenuItem item)
        {
                switch (item.getItemId())
                {
                        case MAIN_HALL:
                                addEvent("MAIN_HALL");
                                Cursor cursor = getEvents();
                            showEvents(cursor);
                                System.out.println ("User click on add Main 
Hall");
                                addRoom("MAIN_HALL");


                                break;

                        case BEDROOM:
                                addEvent("BEDROOM");
                                Cursor cursor1 = getEvents();
                            showEvents(cursor1);
                                System.out.println ("User click on Bedroom");
                                addRoom("BEDROOM");
                                break;

                        case KITCHEN:
                                addEvent("KITCHEN");
                                Cursor cursor2 = getEvents();
                            showEvents(cursor2);
                                System.out.println ("User click on Kitchen");
                                addRoom("KITCHEN");

                                break;

                        case BATHROOM:
                                addEvent("BATHROOM");
                                Cursor cursor3 = getEvents();
                            showEvents(cursor3);
                                System.out.println ("User click on Bathroom");
                                addRoom("BATHROOM");

                                break;

                        case R.id.quit:
                                System.out.println ("user selects quit");
                                break;

                }
                return false;
        }

         public boolean onPrepareOptionsMenu(Menu menu)
         {
                   System.out.println ("inside onPreapareOptionMenu");
                   return true;
         }

        public void onClick (View v)
        {

        }

         public void onDestroy()
         {
                 super.onDestroy();
                 eventsData.close();
         }

         private void addEvent(String title)
         {
                    SQLiteDatabase db = eventsData.getWritableDatabase();
                    ContentValues values = new ContentValues();
                    //values.put(EventDataSQLHelper.TIME, title);
                    values.put(EventDataSQLHelper.TITLE, title);
                    db.insert(EventDataSQLHelper.TABLE, null, values);

          }

          private Cursor getEvents()
          {
                    SQLiteDatabase db = eventsData.getReadableDatabase();
                    Cursor cursor = db.query(EventDataSQLHelper.TABLE, null, 
null,
null, null, null, null);

                    startManagingCursor(cursor);
                    return cursor;
          }

          private void showEvents(Cursor cursor)
          {
                     ret = new StringBuilder("Saved Events:\n\n");
                     while (cursor.moveToNext())
                     {
                         long id = cursor.getLong(0);
                         long time = cursor.getLong(1);
                         String title = cursor.getString(2);
                         ret.append(id + ":"+title + "\n");
                     }
                     System.out.println (ret);

          }

          public void addRoom(String str)
          {
                        setContentView(R.layout.text);
                    output = (TextView) findViewById(R.id.text);
                    output.setText(ret);
          }


}

and this is my.xml file
<?xml version="1.0" encoding="utf-8"?>

<ScrollView
   xmlns:android="http://schemas.android.com/apk/res/android";
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <TextView
      android:id="@+id/text"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" />
</ScrollView>

It creates rows when I hit menu button (after hitting add room submenu
button). But what I want is - create 2 columns for each row.
If you are not understanding this code well, then please give me just
example in which after clicking button it creates row and 2 columns
for each row.

Thanks

On Oct 15, 10:08 am, TreKing <[email protected]> wrote:
> On Thu, Oct 14, 2010 at 11:58 PM, pramod.deore 
> <[email protected]>wrote:
>
> > I had tried but can't succeed.
>
> What did you try?
>
> -------------------------------------------------------------------------------------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices

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