I have a ListView. I want to dynamically change the contents of the listview.I used "adapter.notifyDataSetChanged();" to change the contents. I have also tried setting the adapter of the listview to null but still I get the same results. It is refreshing but not clearing the listview, instead it is appending it with the previous results. What i want is the previous contents should be deleted and the new results should be displayed.
I am not able to understand where is my mistake and what i am missing.
I would be Thankful if someone could please help me out with this.
Below is the code that generates the listview
public void ListDrawer() {
try {
JSONObject jsonResponse = new JSONObject(jsonResult);
JSONArray jsonMainNode = jsonResponse.optJSONArray("myRegisteredList");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String registered_name = jsonChildNode.optString("seminar");
String org = jsonChildNode.optString("organizer");
String sem_id = jsonChildNode.optString("id");
String r_sem = jsonChildNode.optString("seminar_id");
registeredlist = new HashMap<String, String>();
registeredlist.put("registeredList", registered_name);
registeredlist.put("seminar_id", r_sem);
registeredlist.put("sem_id", sem_id);
registeredlist.put("organizer", org);
registeredList.add(registeredlist);
}
} catch (JSONException e) {
//Toast.makeText(this, e.getMessage().toString() + " 1", Toast.LENGTH_LONG).show();
Toast.makeText(ViewReservedSeminarList.this, "Sorry...You don't have any reserved seminar/s.", Toast.LENGTH_LONG).show();
}
try{
simpleAdapter = new SimpleAdapter(this, registeredList,
android.R.layout.simple_list_item_2,
new String[] { "registeredList" ,"organizer", "seminar_id" }, new int[] { android.R.id.text1 , android.R.id.text2 , android.R.id.title });
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
// TODO Auto-generated method stub
#SuppressWarnings("unchecked")
HashMap<String, String> selected_row = (HashMap<String, String>) simpleAdapter.getItem(i);
s_id = selected_row.get("seminar_id");
Intent intent = new Intent(ViewReservedSeminarList.this, ReservedSeminar.class);
startActivity(intent);
//Toast.makeText(ViewReservedSeminarList.this, "Selected Item : "+s_id, Toast.LENGTH_LONG).show();
}
});
}catch(Exception e){
//Toast.makeText(this, e.getMessage().toString() + " 2", Toast.LENGTH_LONG).show();
Toast.makeText(ViewReservedSeminarList.this, "There is no data being fetched", Toast.LENGTH_LONG).show();
}
}
Below is the snippet I placed on the onCreate method to refresh the listview every 10 seconds. I am calling the ListDrawer method under the accessWebService method.
final Handler handler = new Handler();
handler.postDelayed( new Runnable(){
#Override
public void run(){
accessWebService();
handler.postDelayed(this, 10 * 1000);
Log.i("TAG", "notify");
}
}, 10 * 1000
);
Try this please:
Clear the arraylist/HashMap
Add new items
adapter.notifyDataSetChanged();
set adapter.
If you use an ArrayAdapter instead of a SimpleAdapter you can call
ArrayAdapter.clear();
ArrayAdapter.notifyDataSetChanged();
To remove all the elements from the adapter.
Try This
final Handler handler = new Handler();
handler.postDelayed( new Runnable(){
#Override
public void run(){
//this line i have added in your code
registeredList.clear();
accessWebService();
handler.postDelayed(this, 10 * 1000);
Log.i("TAG", "notify");
}
}, 10 * 1000
);
remove adapter.notifyDataSetChanged(); hope it works
Related
Ive been searching for the right answer but nothing can solve my problems. I have a list view which is populated by my database from webserver. So basically what need is to get the data from the listview that is checked by user and pass the data to another activity. Sorry for my bad english hope you guys can help me.
Error ive received
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at firin.myuploads.Attendance$1.onClick(Attendance.java:74)
Attendance.java
public class Attendance extends AppCompatActivity {
//For Checkbox
ArrayList<String> selectedItems=new ArrayList<>();
private String TAG = MainActivity.class.getSimpleName();
private ProgressDialog pDialog;
private ListView lv;
private CheckBox cb;
private Button bGet;
//private id[] id;
private static String url = "www.myphpurl.com";
ArrayList<HashMap<String, String>> contactList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attendance);
contactList = new ArrayList<>();
bGet = (Button) findViewById(R.id.button7);
lv = (ListView) findViewById(R.id.list);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
new GetContacts().execute();
bGet.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// String selected =((TextView)view.findViewById(R.id.mobile)).getText().toString();
CheckBox cb = (CheckBox) findViewById(R.id.cb);
cb.setChecked(true);
int len = lv.getCount();
SparseBooleanArray checked = lv.getCheckedItemPositions();
for (int i = 0; i < len; i++)
if (checked.get(i)) {
String item = selectedItems.get(i);
Toast.makeText(getApplicationContext(), item, Toast.LENGTH_LONG).show();
/*some code to save data in MainActivity*/
Intent in = new Intent(Attendance.this, SendMail.class);
in.putExtra("ListValue", item);
startActivity(in);}
}
});
}
This is the code where i populate my data to the listview
public class GetContacts extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray result = jsonObj.getJSONArray("result");
// looping through All Contacts
for (int i = 0; i < result.length(); i++) {
JSONObject c = result.getJSONObject(i);
String id = c.getString("userID");
String studentName = c.getString("studentName");
String parentName = c.getString("parentName");
String parentEmail = c.getString("parentEmail");
// tmp hash map for single contact
HashMap<String, String> contact = new HashMap<>();
// adding each child node to HashMap key => value
contact.put("UID", id);
contact.put("sName", studentName);
contact.put("pName", parentName);
contact.put("pEmail", parentEmail);
// adding contact to contact list
contactList.add(contact);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});
}
} else {
Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
}
return null;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(Attendance.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
public void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
Attendance.this, contactList,
R.layout.list_item, new String[]{"sName", "pName",
"pEmail"}, new int[]{R.id.name,
R.id.email, R.id.mobile});
lv.setAdapter(adapter);
}
}
Is this how i set my setOnClick?
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String selected =((TextView)findViewById(R.id.mobile)).getText().toString();
CheckBox cb = (CheckBox) findViewById(R.id.cb);
cb.setChecked(true);
}});
Hope you guys can help me. thanks in advance
First you need to get how many item is selected in the listview, then after store in another array and pass that array to another activity.
Set you listview selection mode as Multi Choice.
listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Set Listener on listview as below
ArrayList<String> selectedItem = new ArrayList();
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
view.setSelected(true);
adapter.getView(position, view, parent).setBackgroundColor(getResources().getColor(R.color.btn_login));
adapter.notifyDataSetChanged();
Log.i(TAG, "Selected Item is " + stateList.get(position));
selectedItem.add(yourArray.get(position))
}
});
you can invok your intent and pass selectedItem to that intent like this
Intent intent = new Intent(activity, YourActivity.class);
intent.putStringArrayListExtra("selected_list", selectedItem);
startActivity(intent);
and In your receiving intent you need to do:
ArrayList<String> selectedItem;
Intent i = getIntent();
selectedItem = i.getStringArrayListExtra("selected_list");
i have a list view data come from server and show on the list view . i want listview refresh every 10 sec how can i do this here is my code of list view .
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for (int i = 0; i < peoples.length(); i++) {
JSONObject c = peoples.getJSONObject(i);
String data = c.getString(TAG_DATA);
final String dataaaa = rcdata.getText().toString().trim();
HashMap<String, String> user_data = new HashMap<String, String>();
user_data.put(TAG_DATA, data);
personList.add(user_data);
}
ListAdapter adapter = new SimpleAdapter(
DataSendActivity.this, personList, R.layout.layout_chat,
new String[]{TAG_DATA},
new int[]{R.id.data}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
How repeat a piece of code in a fixed interval, in this case update listview
//instance variable for adapter
ListAdapter adapter;
//instance variable for timer
Timer timer;
//create the listview, adapter and set the adapter
public void showList(){
//method code;
adapter=//call adapter constructor
listView.setSetAdapter(adapter);
//create a handler to update the adapter
final Hanlder handler=new Handler(){
//run your listview update command here. Possibly;
adapter.notifyDataSetChanged();
//or else create a new adapter
adapter=new ListAdapter(//parameters);
listView.setAdapter(adapter);
}
//create timer and the scheduled task
//this will run in every 10 seconds. Make sure to stop it when you dont
//want it any more
timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
handler.obtainMessage().sendToTarget();
}
}, 0, 10000);
}
//if you want to stop the timer on onDestroy()
#Override
public void onDestroy(){
super.onDestroy();
if(timer!=null){
timer.cancel();
}
}
The code is as an example only.
this is a pice of my code and i use async task to search from database and fill the listview using simple adapter.
protected String doInBackground(String... arg0)
{
Cursor TROWS;
ArrayList<HashMap<String, String>> LstViw_VItem=new ArrayList<HashMap<String,String>>();
HashMap<String, String>VMap;
try
{
DBH.openDataBase();
SQLiteDatabase SQLITE=SQLiteDatabase.openDatabase(myPath, null, Context.MODE_PRIVATE);
if (TxtVerminSearch.getText().length()==0)
{
TROWS=SQLITE.rawQuery("select id,vermin_name from pistachio_vermins", null);
}
else
{
TROWS=SQLITE.rawQuery("select id,vermin_name from pistachio_vermins where vermin_name like '%"+TxtVerminSearch.getText()+"%'", null);
}
if (TROWS.moveToFirst())
{
do
{
String VID =TROWS.getString(0);
String VName =TROWS.getString(1);
VMap=new HashMap<String, String>();
VMap.put("VerminID", VID);
VMap.put("VerminName", VName);
LstViw_VItem.add(VMap);
}
while (TROWS.moveToNext());
SimpleAdapter SA=new SimpleAdapter(getApplicationContext(), LstViw_VItem, R.layout.xvermin_items, new String[]{"VerminID","VerminName"}, new int[]{R.id.mainmenu_items__lbl_vermin_id,R.id.mainmenu_items__lbl_vermins});
LstViwVerminItems.setAdapter(SA);
LstViwVerminItems.setEnabled(true);
}
else
{
VMap=new HashMap<String, String>();
VMap.put("VerminID", "-1");
VMap.put("VerminName", "nothing found");
VMap.put("ImgViw",String.valueOf(R.drawable.warning_48));
LstViw_VItem.add(VMap);
SimpleAdapter SA=new SimpleAdapter(getApplicationContext(), LstViw_VItem, R.layout.xvermin_items, new String[]{"VerminID","VerminName","ImgViw"}, new int[]{R.id.mainmenu_items__lbl_vermin_id,R.id.mainmenu_items__lbl_vermins,R.id.mainmenu_items__ImgViw});
LstViwVerminItems.setAdapter(SA);
LstViwVerminItems.setEnabled(false);
}
}
catch (Exception e)
{
final String errString;
errString=e.getMessage();
Log.d("ERR: ", errString);
runOnUiThread(new Runnable()
{
public void run()
{
Toast.makeText(JAct_Vermins.this, errString, Toast.LENGTH_LONG).show();
}
});
}
return null;
}
every thing work fine but when result of search is empty i give an error like this:
Only the original thread that created a view hierarchy can touch its views.
and the problem happen on the this line
VMap.put("ImgViw",String.valueOf(R.drawable.warning_48));
befor of this, i use runOnUiThread function to access ui. but i can not do it right now because i can not declare VMap as final
try to declare HashMap<String, String> VMap; outside doInBackgound() and use runOnUiThread(). If it still doesn't work, try to create a Handler and pass your hashmap key-val as Message.
Note: Declare your VMap variable outside doInBackground()
example:
HashMap<String, String> VMap;
#Override
protected String doInBackground(String... params) {
Cursor TROWS;
ArrayList<HashMap<String, String>> LstViw_VItem = new ArrayList<HashMap<String, String>>();
try {
DBH.openDataBase();
SQLiteDatabase SQLITE = SQLiteDatabase.openDatabase(myPath, null,
Context.MODE_PRIVATE);
if (TxtVerminSearch.getText().length() == 0) {
TROWS = SQLITE.rawQuery("select id,vermin_name from pistachio_vermins", null);
} else {
TROWS = SQLITE.rawQuery(
"select id,vermin_name from pistachio_vermins where vermin_name like '%"
+ TxtVerminSearch.getText() + "%'", null);
}
if (TROWS.moveToFirst()) {
do {
String VID = TROWS.getString(0);
String VName = TROWS.getString(1);
VMap = new HashMap<String, String>();
VMap.put("VerminID", VID);
VMap.put("VerminName", VName);
LstViw_VItem.add(VMap);
} while (TROWS.moveToNext());
SimpleAdapter SA = new SimpleAdapter(getApplicationContext(), LstViw_VItem,
R.layout.xvermin_items, new String[] { "VerminID", "VerminName" },
new int[] { R.id.mainmenu_items__lbl_vermin_id,
R.id.mainmenu_items__lbl_vermins });
LstViwVerminItems.setAdapter(SA);
LstViwVerminItems.setEnabled(true);
} else {
VMap = new HashMap<String, String>();
VMap.put("VerminID", "-1");
VMap.put("VerminName", "nothing found");
mHandler.sendEmptyMessage(0);
LstViw_VItem.add(VMap);
SimpleAdapter SA = new SimpleAdapter(getApplicationContext(), LstViw_VItem,
R.layout.xvermin_items, new String[] { "VerminID", "VerminName",
"ImgViw" }, new int[] { R.id.mainmenu_items__lbl_vermin_id,
R.id.mainmenu_items__lbl_vermins, R.id.mainmenu_items__ImgViw });
LstViwVerminItems.setAdapter(SA);
LstViwVerminItems.setEnabled(false);
}
} catch (Exception e) {
final String errString;
errString = e.getMessage();
Log.d("ERR: ", errString);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(JAct_Vermins.this, errString, Toast.LENGTH_LONG).show();
}
});
}
return null;
}
private Handler mHandler = new Handler(){
#Override
public void handleMessage(Message msg) {
VMap.put("ImgViw", String.valueOf(R.drawable.warning_48));
super.handleMessage(msg);
}
};
Hope it helps!
You should use the method onPostExecute to show the result at your UI. Learn more about AsyncTask. You shouldn't handle with UI at the doInBackground method.
You are trying to update listview from background which is wrong.
For updating ui android provide post execute method , you should write code for updating listview in postexecute method. For your reference you can see this link http://www.compiletimeerror.com/2013/01/why-and-how-to-use-asynctask.html
function doInBackgound() - cannot call function from ui tread
use runOnUiThread() or onPostExecute()
I know there are many questions asking about returning to the last position scrolled when the list has been refreshed. However I don't know why in my case (Adapter) the given answers don't work.
I have an adapter where at a given time it refreshes with new info and loads it in the adapter. What I want is that when it refreshes not come again to the top of the adapter and save the previous state.
Here is the code I use.
OnCreate
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_candidatos);
if (Titulacion.IsReachable1(getApplicationContext())){
new CargarCandidatos().execute();
timer();
}else{
Toast.makeText(getApplicationContext(), R.string.errorserver, Toast.LENGTH_LONG).show();
}
setListAdapter(adapter);
candidatosList = new ArrayList<HashMap<String, String>>();
The asynctask is divided in 2 parts. The retrieval of information and adapting the data into the adapter.
Here is the code of adapting it:
protected void onPostExecute(String file_url) {
runOnUiThread(new Runnable() {
public void run() {
adapter = new SimpleAdapter(
Monitorizacion.this, candidatosList,
R.layout.list_item, new String[] { TAG_ID,TAG_NSERIE,TAG_TABLET,
TAG_DNI, TAG_NOMBRE, TAG_TEST, TAG_PREGUNTA, TAG_BATERIA,TAG_CORRECTAS, TAG_ERRORES},
new int[] { R.id.autoid,R.id.id,R.id.tablet, R.id.dni, R.id.nombre, R.id.test, R.id.pregunta, R.id.bateria, R.id.correctas, R.id.fallos});
adapter.notifyDataSetChanged();
setListAdapter(adapter);
}
});
}
But how should I save the state of the adapter and then start showing the items considering the previous state.
Thank you
Edit: I have tried the answer approbed here Maintain/Save/Restore scroll position when returning to a ListView, but I cannot make it work.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_candidatos);
if (Titulacion.IsReachable1(getApplicationContext())){
new CargarCandidatos().execute();
timer();
}else{
Toast.makeText(getApplicationContext(), R.string.errorserver, Toast.LENGTH_LONG).show();
}
setListAdapter(adapter);
candidatosList = new ArrayList<HashMap<String, String>>();
lv = (ListView)findViewById(android.R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String idd = ((TextView) view.findViewById(R.id.dni)).getText()
.toString();
Intent in = new Intent(getApplicationContext(),
MonitDetail.class);
in.putExtra("idd", idd);
startActivityForResult(in, 100);
}
});
}
//
//
public void timer(){
new CountDownTimer(tiempo, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
index = lv.getFirstVisiblePosition();
v = lv.getChildAt(0);
top = (v == null) ? 0 : v.getTop();
if (Titulacion.IsReachable1(getApplicationContext())){
new CargarCandidatos().execute();
timer();
}else{
Toast.makeText(getApplicationContext(), R.string.errorserver, Toast.LENGTH_LONG).show();
}
}
}.start();}
class CargarCandidatos extends AsyncTask<String, Void, String> {
protected String doInBackground(String... args) {
try {
monitorizar();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}
return null;
}
protected void onPostExecute(String file_url) {
runOnUiThread(new Runnable() {
public void run() {
adapter = new SimpleAdapter(
Monitorizacion.this, candidatosList,
R.layout.list_item, new String[] { TAG_ID,TAG_NSERIE,TAG_TABLET,
TAG_DNI, TAG_NOMBRE, TAG_TEST, TAG_PREGUNTA, TAG_BATERIA,TAG_CORRECTAS, TAG_ERRORES},
new int[] { R.id.autoid,R.id.id,R.id.tablet, R.id.dni, R.id.nombre, R.id.test, R.id.pregunta, R.id.bateria, R.id.correctas, R.id.fallos});
lv.setSelectionFromTop(index, top);
adapter.notifyDataSetChanged();
lv.setAdapter(adapter);
}
});
}
}
public void monitorizar() throws Exception{
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("fecha",Titulacion.fecha()));
JSONObject json = jParser.makeHttpRequest(url_candidatos, "GET", params);
ArrayList<HashMap<String, String>> temp;
temp = new ArrayList<HashMap<String, String>>();
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
candidatos = json.getJSONArray(TAG_CANDIDATOS);
for (int i = 0; i < candidatos.length(); i++) {
JSONObject c = candidatos.getJSONObject(i);
String id = c.getString(TAG_ID);
String nserie = c.getString(TAG_NSERIE);
String tablet = c.getString(TAG_TABLET);
String dni = c.getString(TAG_DNI);
String nombre = c.getString(TAG_NOMBRE);
String test = c.getString(TAG_TEST);
String pregunta = c.getString(TAG_PREGUNTA);
String bateria = c.getString(TAG_BATERIA);
String correctas = c.getString(TAG_CORRECTAS);
String errores = c.getString(TAG_ERRORES);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_NSERIE, nserie);
map.put(TAG_TABLET, tablet);
map.put(TAG_DNI, dni);
map.put(TAG_NOMBRE, nombre);
map.put(TAG_TEST, test);
map.put(TAG_PREGUNTA, pregunta);
map.put(TAG_BATERIA, bateria);
map.put(TAG_CORRECTAS, correctas);
map.put(TAG_ERRORES, errores);
temp.add(map);
candidatosList = temp;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
You can use like this
getListView().setSelection(position);
method of your ListView.
where you can get 'position' from the length of list you are passing to the adapter.
Declare you listview Globally and then you can keep the last position before New-Data-call. After then you can call listview for a position selection.
I use internet service to fill a list view. I want to refresh the list view items when user press the refresh button. how can i do this?
In AsyncTask and postExecute i fill the list view:
protected void onPostExecute(String file_url) {
pDialog.dismiss();
try {
if (jSon.has(KEY_SUCCESS)) {
String success = jSon.getString(KEY_SUCCESS);
if (success.equals("1")) {
notes = jSon.getJSONObject("notes");
for (int i = 0; i < notes.length(); i++) {
JSONObject c = notes.getJSONObject(Integer
.toString(i));
Log.i("JSONObject c >>", c.toString());
String id = c.getString(KEY_NOTE_ID);
String subject = c.getString(KEY_NOTE_SUBJECT);
String date = c.getString(KEY_NOTE_DATE);
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_NOTE_ID, id);
map.put(KEY_NOTE_SUBJECT, subject);
map.put(KEY_NOTE_DATE, date);
noteList.add(map);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(AllNotes.this,
noteList, R.layout.list_item, new String[] {
KEY_NOTE_ID, KEY_NOTE_SUBJECT,
KEY_NOTE_DATE }, new int[] {
R.id.list_lbl_id, R.id.list_lbl_subject,
R.id.list_lbl_date });
setListAdapter(adapter);
}
});
}
The most basic approach is to empty noteList and run your AsyncTask again.
Inside onPreExecute() (or the first line of doInBackground()) call either:
noteList = new ArrayList<Map<String, String>>(); // or noteList.clear();
Call your AsyncTask's execute() method again.
Also I don't believe you need to use runOnUiThread() in onPostExecute() because it already has access to the main thread.