Friday, December 10, 2010

[android-developers] notifyDataSetChanged not updating view

As per the Docs notifyDataSetChanged ()-Notifies the attached View
that the underlying data has been changed and it should refresh
itself. In my application I am calling notifyDataSetChanged but still
my view is not updates automatically. To update view I have to press
Back button and ahain when I return to activity then this time it show
updated view.

Here is my some part of code

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

try
{
.......
myAdapter = new SimpleCursorAdapter(this,
R.layout.roomswitchlist, c, columns,names);
setListAdapter(myAdapter);
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (menuItemName.equalsIgnoreCase("Remove Switch"))
{
..............
public void onClick(DialogInterface dialog, int id)
{
// Action for 'Yes' Button
System.out.println ("User click on Yes button");
deleteSwitchID(delRoomName,delSwitchName);
myAdapter.notifyDataSetChanged();

}
}

public void deleteSwitchID(String roomName1,String SwitchName1)
{

try
{
sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, MODE_PRIVATE,
null);
int no = sampleDB.delete(SWITCH_TABLE_NAME, "RoomName =
'"+roomName1+"' and SwitchName = '"+SwitchName1+"'", null);
System.out.println ("No of deleted rows are"+no);
Toast t = new Toast(this);
t.makeText(this, "Switch deleted", Toast.LENGTH_SHORT)
.show();
myAdapter.notifyDataSetChanged();
//this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,results));
//onCreate(savedInstanceState);
//startActivity(getIntent()); //Restarts activity for menu refresh

}
catch (Exception e)
{
e.printStackTrace();
}
}

Why view is not updating instantly?

Thanks


--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment