[android-developers] Re: Again Back button issue

2010-12-10 Thread pramod.deore
Hi, Yuvidroid no I had not called startActivity. Here is my code

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

try
{
System.out.println (Inside try);
//sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
MODE_PRIVATE, null);
sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
MODE_PRIVATE, null);
System.out.println (Inside try...);
Cursor c = sampleDB.rawQuery (SELECT _id,RoomName,
SwitchFullName FROM SwitchTable ,null);
System.out.println (c.getCount()+);
startManagingCursor(c);

System.out.println (After startManagingCursor(c)));
String[] columns = new String[] {RoomName,
SwitchFullName};

int[] names = new int[] {R.id.room, R.id.switch1};

myAdapter = new SimpleCursorAdapter(this,
R.layout.roomswitchlist, c, columns,names);
setListAdapter(myAdapter);


}
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)
{
try
{
info = (AdapterView.AdapterContextMenuInfo) menuInfo;
}
catch (ClassCastException e)
{
e.printStackTrace();
}

long id = getListAdapter().getItemId(info.position);
Object obj = getListAdapter().getItem((int) id);
System.out.println (!!!@@@+obj.toString());
str = obj.toString();
System.out.println ($+str);
/*rName = str.substring(0,str.indexOf(-));
sName = str.substring(str.indexOf(-)+1);

test = true;*/

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

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

  cursor = (Cursor) myAdapter.getItem((int) id);
  //long phoneId =
cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID));
}

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

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

System.out.println (+menuItemName);

if (menuItemName.equalsIgnoreCase(Add Switch))
{
System.out.println (Inside Add Switch);

}

else if (menuItemName.equalsIgnoreCase(Remove Switch))
{
System.out.println (Inside Remove switch);

delRoomName =
cursor.getString(cursor.getColumnIndex(RoomName)-1);
System.out.println (Delete Room  name +delRoomName);
delSwitchName =
cursor.getString(cursor.getColumnIndex(SwitchFullName));
System.out.println (Delete Room  name and switch name
are+delRoomName+:+delSwitchName);

AlertDialog.Builder alt_bld = new 
AlertDialog.Builder(this);
alt_bld.setMessage(Do you want to Delete +delSwitchName
+ ?)
.setCancelable(false)
.setPositiveButton(Yes, new
DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
// Action for 'Yes' Button
System.out.println (User click on Yes button);
deleteSwitchID(delRoomName,delSwitchName);
}
})

.setNegativeButton(No, new
DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
//  Action for 'NO' Button
System.out.println (User click on No button);
//dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog

Re: [android-developers] Re: Again Back button issue

2010-12-10 Thread YuviDroid
Ehmwhat's this: ?
startActivity(getIntent()); //Restarts activity for menu refresh


On Fri, Dec 10, 2010 at 10:24 AM, pramod.deore deore.pramo...@gmail.comwrote:

 Hi, Yuvidroid no I had not called startActivity. Here is my code

 public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

try
{
System.out.println (Inside try);
//sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
 MODE_PRIVATE, null);
sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
 MODE_PRIVATE, null);
System.out.println (Inside try...);
Cursor c = sampleDB.rawQuery (SELECT _id,RoomName,
 SwitchFullName FROM SwitchTable ,null);
System.out.println (c.getCount()+);
startManagingCursor(c);

System.out.println (After startManagingCursor(c)));
String[] columns = new String[] {RoomName,
 SwitchFullName};

int[] names = new int[] {R.id.room, R.id.switch1};

myAdapter = new SimpleCursorAdapter(this,
 R.layout.roomswitchlist, c, columns,names);
setListAdapter(myAdapter);


}
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)
{
try
{
info = (AdapterView.AdapterContextMenuInfo) menuInfo;
}
catch (ClassCastException e)
{
e.printStackTrace();
}

long id = getListAdapter().getItemId(info.position);
Object obj = getListAdapter().getItem((int) id);
System.out.println (!!!@@@+obj.toString());
str = obj.toString();
System.out.println ($+str);
/*rName = str.substring(0,str.indexOf(-));
sName = str.substring(str.indexOf(-)+1);

test = true;*/

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

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

  cursor = (Cursor) myAdapter.getItem((int) id);
  //long phoneId =
 cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID));
}

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

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

System.out.println (+menuItemName);

if (menuItemName.equalsIgnoreCase(Add Switch))
{
System.out.println (Inside Add Switch);

}

else if (menuItemName.equalsIgnoreCase(Remove Switch))
{
System.out.println (Inside Remove switch);

delRoomName =
 cursor.getString(cursor.getColumnIndex(RoomName)-1);
System.out.println (Delete Room  name
 +delRoomName);
delSwitchName =
 cursor.getString(cursor.getColumnIndex(SwitchFullName));
System.out.println (Delete Room  name and switch
 name
 are+delRoomName+:+delSwitchName);

AlertDialog.Builder alt_bld = new
 AlertDialog.Builder(this);
alt_bld.setMessage(Do you want to Delete +delSwitchName
 + ?)
.setCancelable(false)
.setPositiveButton(Yes, new
 DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
// Action for 'Yes' Button
System.out.println (User click on Yes
 button);
deleteSwitchID(delRoomName,delSwitchName);
}
})

.setNegativeButton(No, new
 DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
//  Action for 'NO' Button
System.out.println (User click on No
 button);

[android-developers] Re: Again Back button issue

2010-12-10 Thread pramod.deore
Ohh!! I just coy and paste that previous code, and by mistake I forgot
to remove that line. But now after removing
startActivity(getIntent());  item is deleted but list is not updated
instantly.
I read somewhere I must have to use notifyDataSetChanged();  How to
use this?

On Dec 10, 2:29 pm, YuviDroid yuvidr...@gmail.com wrote:
 Ehmwhat's this: ?
 startActivity(getIntent()); //Restarts activity for menu refresh

 On Fri, Dec 10, 2010 at 10:24 AM, pramod.deore 
 deore.pramo...@gmail.comwrote:



  Hi, Yuvidroid no I had not called startActivity. Here is my code

  public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);

         try
         {
                 System.out.println (Inside try);
                 //sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
  MODE_PRIVATE, null);
                 sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
  MODE_PRIVATE, null);
                 System.out.println (Inside try...);
                 Cursor c = sampleDB.rawQuery (SELECT _id,RoomName,
  SwitchFullName FROM SwitchTable ,null);
                 System.out.println (c.getCount()+);
                 startManagingCursor(c);

                 System.out.println (After startManagingCursor(c)));
                                 String[] columns = new String[] {RoomName,
  SwitchFullName};

                 int[] names = new int[] {R.id.room, R.id.switch1};

                 myAdapter = new SimpleCursorAdapter(this,
  R.layout.roomswitchlist, c, columns,names);
                 setListAdapter(myAdapter);

         }
         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)
         {
                 try
                 {
                     info = (AdapterView.AdapterContextMenuInfo) menuInfo;
                 }
                 catch (ClassCastException e)
                 {
                         e.printStackTrace();
                 }

                 long id = getListAdapter().getItemId(info.position);
                 Object obj = getListAdapter().getItem((int) id);
                 System.out.println (!!!@@@+obj.toString());
                 str = obj.toString();
                 System.out.println ($+str);
                 /*rName = str.substring(0,str.indexOf(-));
                 sName = str.substring(str.indexOf(-)+1);

                 test = true;*/

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

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

                   cursor = (Cursor) myAdapter.getItem((int) id);
               //long phoneId =
  cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID));
         }

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

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

                 System.out.println (+menuItemName);

                 if (menuItemName.equalsIgnoreCase(Add Switch))
                 {
                         System.out.println (Inside Add Switch);

                 }

                 else if (menuItemName.equalsIgnoreCase(Remove Switch))
                 {
                         System.out.println (Inside Remove switch);

                         delRoomName =
  cursor.getString(cursor.getColumnIndex(RoomName)-1);
                         System.out.println (Delete Room  name
  +delRoomName);
                         delSwitchName =
  cursor.getString(cursor.getColumnIndex(SwitchFullName));
                         System.out.println (Delete Room  name and switch
  name
  are+delRoomName+:+delSwitchName);

                         AlertDialog.Builder alt_bld = new
  AlertDialog.Builder(this);
                 alt_bld.setMessage(Do you want to Delete +delSwitchName
  + ?)
                 .setCancelable(false)
                 .setPositiveButton(Yes, new
  DialogInterface.OnClickListener()
                 {
                         public void onClick(DialogInterface dialog, int id)
                         {
                                 // Action for 'Yes' Button
                                 System.out.println (User click on Yes
  button);
                                 

[android-developers] Re: Again Back button issue

2010-12-10 Thread pramod.deore
How to use notifyDataSetChanged().

On Dec 10, 2:46 pm, pramod.deore deore.pramo...@gmail.com wrote:
 Ohh!! I just coy and paste that previous code, and by mistake I forgot
 to remove that line. But now after removing
 startActivity(getIntent());  item is deleted but list is not updated
 instantly.
 I read somewhere I must have to use notifyDataSetChanged();  How to
 use this?

 On Dec 10, 2:29 pm, YuviDroid yuvidr...@gmail.com wrote:

  Ehmwhat's this: ?
  startActivity(getIntent()); //Restarts activity for menu refresh

  On Fri, Dec 10, 2010 at 10:24 AM, pramod.deore 
  deore.pramo...@gmail.comwrote:

   Hi, Yuvidroid no I had not called startActivity. Here is my code

   public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);

          try
          {
                  System.out.println (Inside try);
                  //sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
   MODE_PRIVATE, null);
                  sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
   MODE_PRIVATE, null);
                  System.out.println (Inside try...);
                  Cursor c = sampleDB.rawQuery (SELECT _id,RoomName,
   SwitchFullName FROM SwitchTable ,null);
                  System.out.println (c.getCount()+);
                  startManagingCursor(c);

                  System.out.println (After startManagingCursor(c)));
                                  String[] columns = new String[] 
   {RoomName,
   SwitchFullName};

                  int[] names = new int[] {R.id.room, R.id.switch1};

                  myAdapter = new SimpleCursorAdapter(this,
   R.layout.roomswitchlist, c, columns,names);
                  setListAdapter(myAdapter);

          }
          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)
          {
                  try
                  {
                      info = (AdapterView.AdapterContextMenuInfo) menuInfo;
                  }
                  catch (ClassCastException e)
                  {
                          e.printStackTrace();
                  }

                  long id = getListAdapter().getItemId(info.position);
                  Object obj = getListAdapter().getItem((int) id);
                  System.out.println (!!!@@@+obj.toString());
                  str = obj.toString();
                  System.out.println ($+str);
                  /*rName = str.substring(0,str.indexOf(-));
                  sName = str.substring(str.indexOf(-)+1);

                  test = true;*/

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

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

                    cursor = (Cursor) myAdapter.getItem((int) id);
                //long phoneId =
   cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID));
          }

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

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

                  System.out.println (+menuItemName);

                  if (menuItemName.equalsIgnoreCase(Add Switch))
                  {
                          System.out.println (Inside Add Switch);

                  }

                  else if (menuItemName.equalsIgnoreCase(Remove Switch))
                  {
                          System.out.println (Inside Remove switch);

                          delRoomName =
   cursor.getString(cursor.getColumnIndex(RoomName)-1);
                          System.out.println (Delete Room  name
   +delRoomName);
                          delSwitchName =
   cursor.getString(cursor.getColumnIndex(SwitchFullName));
                          System.out.println (Delete Room  name and switch
   name
   are+delRoomName+:+delSwitchName);

                          AlertDialog.Builder alt_bld = new
   AlertDialog.Builder(this);
                  alt_bld.setMessage(Do you want to Delete +delSwitchName
   + ?)
                  .setCancelable(false)
                  .setPositiveButton(Yes, new
   DialogInterface.OnClickListener()
                  {
                          public void onClick(DialogInterface dialog, int id)