I have implemented AnyChart in my app and I am using it on 3 different tabs, according to month, week and year. The problem it's that when the fragments are Created, I send a query to the server to return some values, to populate the chart. I have followed the steps according to the github of AnyChart to implement it and it works, but when I switch between the tabs, the charts gets doubled or even tripled. I have implemented the same code for AsyncTask and AnyChart in all of the tabs, according to the number of days. I use the following code for the charts:
private void CreareGraficDinamicInterventie() {
APIlib.getInstance().setActiveAnyChartView(anyChartView);
Cartesian areaChart = AnyChart.area();
areaChart.animation(true);
Crosshair crosshair = areaChart.crosshair();
crosshair.enabled(true);
// TODO yStroke xStroke in crosshair
crosshair.yStroke((Stroke) null, null, null, (String) null, (String) null)
.xStroke("#fff", 1d, null, (String) null, (String) null)
.zIndex(39d);
crosshair.yLabel(0).enabled(false);
areaChart.yScale().stackMode(ScaleStackMode.VALUE);
List<DataEntry> seriesData = new ArrayList<>();
for (int j=data_grafic.size()-1 ; j>0 ; j-- ) {
seriesData.add(new CustomDataEntry(String.valueOf(data_grafic.get(j)), Double.valueOf(timpi_interventie.get(j))));
}
ChartCredits credits = areaChart.credits();
credits.enabled(false);
Set set = Set.instantiate();
set.data(seriesData);
Mapping series1Data = set.mapAs("{ x: 'x' }");
Area series1 = areaChart.area(series1Data);
series1.name("Timp de interventie ");
series1.stroke("3 #fff");
series1.hovered().stroke("3 #fff");
series1.hovered().markers().enabled(true);
series1.hovered().markers()
.type(MarkerType.CIRCLE)
.size(4d)
.stroke("1.5 #fff");
series1.markers().zIndex(100d);
areaChart.legend().enabled(true);
areaChart.legend().fontSize(13d);
areaChart.legend().padding(0d, 0d, 20d, 0d);
areaChart.xAxis(0).title(false);
areaChart.yAxis(0).title("Timp de interventie (h)");
areaChart.interactivity().hoverMode(HoverMode.BY_X);
areaChart.tooltip()
.valuePostfix("h")
.displayMode(TooltipDisplayMode.UNION);
anyChartView.setChart(areaChart);
}
The CreareGrafiDinamicInterventie() gets called after the onPostExecute in the AsyncTask querying the server. I have tried to use anyChartView.clear(); but the chart dissapears, it does not show anything.
This is the AsyncTask called in OnCreateView:
private void GasesteDetaliiSaptamana(){
class GasesteDetaliiSaptamana extends AsyncTask<Void, Void, String> {
User user = SharedPrefManager.getInstance(getContext()).getUser();
final String id_user = String.valueOf(user.getId());
#Override
protected String doInBackground(Void... voids) {
//creating request handler object
RequestHandler requestHandler = new RequestHandler();
//creating request parameters
HashMap<String, String> params = new HashMap<>();
params.put("interval_zile", "6");
//returing the response
return requestHandler.sendPostRequest(URLs.URL_STATISTICIGRAFICE, params);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
//displaying the progress bar while user registers on the server
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
timpi_interventie.clear();
timpi_rezolvare.clear();
data_grafic.clear();
//hiding the progressbar after completion
try {
//converting response to json object
JSONObject obj = new JSONObject(s);
//if no error in response
if (!obj.getBoolean("error")) {
timp_raportare_rezolvare= obj.getString("timp_raportare_rezolvare");
timp_catalogare_rezolvare= obj.getString("timp_catalogare_rezolvare");
timp_raportare_catalogare= obj.getString("timp_raportare_catalogare");
numar_total_alerte_catalogate = obj.getString("numar_total_alerte_catalogate");
numar_alerte_remediate = obj.getString("numar_alerte_remediate");
numar_total_alerte = obj.getString("numar_total_alerte");
timp_mediu_interventie = obj.getString("timp_mediu_interventie");
timp_mediu_rezolvare = obj.getString("timp_mediu_rezolvare");
JSONArray rap_cat = obj.getJSONArray("vector_rap_cat");
for (int i = 0; i < rap_cat.length(); i++) {
JSONObject Rap_cat = rap_cat.getJSONObject(i);
timpi_interventie.add(Rap_cat.getString("rap_cat"));
}
JSONArray rap_rez = obj.getJSONArray("vector_rap_rez");
for (int i = 0; i < rap_rez.length(); i++) {
JSONObject Rap_rez = rap_rez.getJSONObject(i);
timpi_rezolvare.add(Rap_rez.getString("rap_rez"));
}
JSONArray data_alerte = obj.getJSONArray("data_alerte");
for (int i = 0; i < data_alerte.length(); i++) {
JSONObject Data = data_alerte.getJSONObject(i);
data_grafic.add(Data.getString("data"));
}
}
} catch (JSONException ex) {
ex.printStackTrace();
}
CreareGraficDinamicInterventie();
}
}
GasesteDetaliiSaptamana ru =new GasesteDetaliiSaptamana();
ru.execute();
}
I have figured out a way, and I will write it down, maybe in the future it will help others too. I have added in the .xml a linear layout, to where I want my chart to be:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/linear_chart"
android:orientation="horizontal">
</LinearLayout>
And, programically, I've created the chart, and added the view to this layout, removing all the views in the beginning.
private void CreareGraficDinamicInterventie() {
linear_chart.removeAllViews();
AnyChartView anyChartView = new AnyChartView(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.setMargins(10,10,10,10);
params.weight=1;
anyChartView.setLayoutParams(params);
Cartesian areaChart = AnyChart.area();
....
anyChartView.setChart(areaChart);
linear_chart.addView(anyChartView);
}
Combine those with declaring the LinearLayout in onCreate and it should work, deleting the last chart and adding the new one.
Related
The goal here is to retrieve JSON format data from an API, convert the data into an array in android studio. Then to display a random question into a text view and the question will not repeat itself. The question changes everytime a button is clicked. There's something wrong with the logic of how I use my array/parsing the data to the array. I am not sure how to proceed. Any help is appreciated
MY JSON format
{
"error": false,
"message": "Successfully retrieved",
"questions": [
{
"question": "Tell us about yourself?"
},
{
"question": "Tell us about yourself2?"
},
{
"question": "Tell us about yourself3?"
},
{
"question": "Tell us about yourself4?"
},
{
"question": "Tell us about yourself5?"
}
]
}
My code so far ( simplified to this function )
public class MainActivity extends AppCompatActivity {
// create arraylist to store question
List<String> questionList = new ArrayList<>();
// use max to decide the number of question
// use i to find out the number of questions
int i = 10;
int min = 0;
int max = i;
int[] usedInt = new int[max];
//create another array to put all the used integer inside for 0 repeition of question
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView textViewQuestions = (TextView) findViewById(R.id.questionView);
usedInt = new int[i];
Random r = new Random();
int i1 = r.nextInt(max - min + 1) + min;
//generate random number, set textview the question, set int to usedint array
textViewQuestions.setText(questionList.get(i1));
usedInt[0] = i1;
//set first question
findViewById(R.id.changeQuestion).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Log.d(TAG,questionList[updateQuestions(usedInt)]);
//final int[] usedIntTemp = usedInt;
getQuestions();
int n = updateQuestions(usedInt);
textViewQuestions.setText(questionList.get(n));
//finish();
}
});
}
}
public int updateQuestions(int usedInteger[]) {
int min = 0;
int max = i;
Random r = new Random();
int i2 = r.nextInt(max - min + 1) + min;
int uInteger[] = usedInteger;
int l = 0;
while (l != max) {
if (i2 == usedInteger[l]) {
l++;
if (l == max) {
Toast.makeText(getApplicationContext(), "No other questions available", Toast.LENGTH_LONG).show();
}
} else {
usedInteger[usedInteger.length + 1] = i2;
return i2;
}
}
return i2;
}
private void getQuestions()
{
class GetQuestions extends AsyncTask<Void, Void, String> {
//private ProgressBar progressBar;
#Override
protected String doInBackground(Void... voids) {
//creating request handler object
RequestHandler requestHandler = new RequestHandler();
//creating request parameters
HashMap<String, String> params = new HashMap<>();
params.put("role_id", "1");
//returing the response
return requestHandler.sendPostRequest(URLs.URL_QUESTIONS, params);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
//displaying the progress bar while user registers on the server
//progressBar = (ProgressBar) findViewById(R.id.progressBar);
//progressBar.setVisibility(View.VISIBLE);
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//hiding the progressbar after completion
//progressBar.setVisibility(View.GONE);
boolean Error1 = false;
try {
//converting response to json object
JSONObject obj = new JSONObject(s);
//HashMap<String, String> questionJson = new HashMap<>();
// success = obj.getBoolean("error");
if (!obj.getBoolean("error")) {
//Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
//getting the questions from the response
JSONArray questionsJson = obj.getJSONArray("questions");
//creating a new questions object
for (i = 0; i < questionsJson.length(); i++) {
JSONObject object = questionsJson.getJSONObject(i);
questionList.add(object.getString("question"));
Log.d(TAG,"objcheck");
Log.d(TAG,object.getString("question"));
//q = c.getString("question");
//questionJson.put("question", q);
//questionList.add(questionJson);
}
finish();
//startActivity(new Intent(getApplicationContext(), MainActivity.class));
} else {
Toast.makeText(getApplicationContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
GetQuestions gq = new GetQuestions();
gq.execute();
}
Object[] array = new Object[10]; // say 10 objects
int remain = array.length;
Random rnd = new Random();
public Object next () {
if (remain == 0) {
return null;
} else {
int i = rnd.nextInt(remain--);
Object tmp = array[i];
array[i] = array[remain];
array[remain] = tmp;
return tmp;
}
}
This will generate next random question
I tried this, with
getQuestions();
String n = String.valueOf(next());
textViewQuestions.setText(n);
I also populated the array like this
for (i = 0; i < questionsJson.length(); i++) {
JSONObject object = questionsJson.getJSONObject(i);
array[i] = object.getString("question");
questionList.add(object.getString("question"));
Log.d(TAG,object.getString("question"));
}
However, the questions do repeat but will only show a set amount of questions. :( How to make the questions not repeat?
Hi I'm working on CardSwipe functionality like tinder. (For understanding see the attached image)
For this i followed this code, when using static data like bellow, I'm successfully adding items in ListView
private void loadCards2(){
itemsaArrayList = new ArrayList<>();
for(int i = 0; i < 10; i++){
CardSwipeItems items = new CardSwipeItems();
items.setCardImageUrl("http://i.ytimg.com/vi/PnxsTxV8y3g/maxresdefault.jpg");
items.setCardDescription("But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness.");
itemsaArrayList.add(items);
}
flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
myAppAdapter = new CardSwipeAdapter(itemsaArrayList, CardSwipeActivity.this);
flingContainer.setAdapter(myAppAdapter);
initControlls();
}
But when I'm trying to add the items dynamically by using volley means, items are not adding in the ListView. (For this volley
please see the loadCards() method in the CardSwipeActivity)
I tried lot of approaches to load the items in the list view dynamically. For ex: I used Thread (For code see this) and i also used Handler (For code see this) but I'm not able to add the items in ListView dynamically
If any one know the solution for this means please tell me. Thank you.......
Edit
*My method*
private void loadCards(){
String Url = "myApi";
Log.e("Url", Url);
final ProgressDialog dialog = ProgressDialog.show(CardSwipeActivity.this, null, null);
ProgressBar spinner = new android.widget.ProgressBar(CardSwipeActivity.this, null,android.R.attr.progressBarStyle);
spinner.getIndeterminateDrawable().setColorFilter(Color.parseColor("#009689"), android.graphics.PorterDuff.Mode.SRC_IN);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(spinner);
dialog.setCancelable(false);
dialog.show();
StringRequest request = new StringRequest(Request.Method.GET, Url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
dialog.dismiss();
if(response != null && !response.startsWith("<HTML>")){
Log.e("OnResponse", response);
try {
JSONArray jsonArray = new JSONArray(response);
if(jsonArray.length() > 0){
itemsaArrayList = new ArrayList<>();
for(int i = 0; i< jsonArray.length(); i++){
JSONObject singleObj = jsonArray.getJSONObject(i);
String imgId = singleObj.getString("avatar_file_id");
String name = singleObj.getString("name");
CardSwipeItems items = new CardSwipeItems();
Log.e("imgId", imgId);
Log.e("name", name);
items.setCardImageUrl(imgId);
items.setCardDescription(name);
itemsaArrayList.add(items);
}
flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
myAppAdapter = new CardSwipeAdapter(itemsaArrayList, CardSwipeActivity.this);
flingContainer.setAdapter(myAppAdapter);
initControlls();
}
} catch (JSONException e) {
e.printStackTrace();
}
}else{
Log.e("Internet", "Internet");
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
dialog.dismiss();
if(error != null){
Log.e("error", error.toString());
}else{
}
}
}){
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("token","b32daf7b50c7f21dba80dd0651174e3839c22f56");
params.put("user_id","386");
Log.e("Headers", "**********Headers*************");
Log.e("token","b32daf7b50c7f21dba80dd0651174e3839c22f56");
Log.e("user_id","386");
return params;
}
};
RequestQueue queue = Volley.newRequestQueue(CardSwipeActivity.this);
queue.add(request);
queue.getCache().remove(Url);
}
You can add items dynamically to the adapter by addding items to the list you passed originally to adapter like this:
itemsaArrayList.add(items);
than you need to notify the adapter like this from your UI thread:
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
});
And to call it on the UI-Thread, use have to use runOnUiThread() of Activity. Then only, notifyDataSetChanged() will work.
Also have a look at this post
If you are getting response from server then try to move below line from onResponse method to onCreate method.
flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
Hope this will work
I have gridview which load few images thumbnails. When I click on some image is opened in new activity full image. Now I trying to add some description about the image. When activity is loaded the info for this image is loaded also. So far so good..
The problem comes when I click on button next which load next image(full image without to back on the gridview with thumbnails) the description doesn't update and change for the next image. Is just same description for every image.
Here I download thumb, full_image and description,
String url = "http://myhost/get.php?id=" + my_id;
JSONArray data;
try {
resultServer = getJSONUrl(url);
data = new JSONArray(resultServer);
MyArrList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, Object>();
map.put("id", (String)c.getString("id"));
map.put("description", (String)c.getString("description"));
// Thumbnail Get ImageBitmap To Bitmap
map.put("ImagePathThum", (String)c.getString("image"));
map.put("ImageThumBitmap", (Bitmap)loadBitmap(c.getString("image")));
// Full (for View Full)
map.put("ImagePathFull", (String)c.getString("image_big"));
MyArrList.add(map);
}
Then this is the gridView() which display thumbs
public void ShowAllContent()
{
// gridView1
final GridView gridV = (GridView)findViewById(R.id.gridView1);
gridV.setAdapter(new ImageAdapter(act1.this,MyArrList));
// OnClick
gridV.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
String Position = String.valueOf(position);
Intent newActivity = new Intent(act1.this,act2.class);
newActivity.putExtra("Position", Position);
newActivity.putExtra("resultServer", resultServer);
newActivity.putExtra("description", MyArrList.get(position).get("description").toString());
startActivity(newActivity);
finish();
}
});
}
Then In act2
TextView txtView;
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information);
txtView = (TextView) findViewById(R.id.text);
Intent intent= getIntent();
curPosition = Integer.parseInt(intent.getStringExtra("Position"));
resultServer = String.valueOf(intent.getStringExtra("resultServer"));
textDescription = getIntent().getStringExtra("description");
((TextView)findViewById(R.id.text)).setText(textDescription+"");
try {
MyArrList = ConvertJSONtoArrayList(resultServer);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("ArrayList Size",String.valueOf(MyArrList.size()));
// Show Image Full
new DownloadFullPhotoFileAsync().execute();
// Button Back
back = (Button) findViewById(R.id.btnBack);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
curPosition = curPosition - 1;
new DownloadFullPhotoFileAsync().execute();
}
});
// Button Next
next = (Button) findViewById(R.id.btnNext);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
curPosition = curPosition + 1;
new DownloadFullPhotoFileAsync().execute();
}
});
}
// Show Image Full
public void ShowImageFull(String imageName, Bitmap imgFull)
{
// Prepare Button (Back)
if(curPosition <= 0)
{
back.setEnabled(false);
}
else
{
back.setEnabled(true);
}
// Prepare Button (Next)
Log.d("curPosition",String.valueOf(curPosition));
Log.d("MyArrList.size",String.valueOf(MyArrList.size()));
if(curPosition >= MyArrList.size() - 1)
{
next.setEnabled(false);
}
else
{
next.setEnabled(true);
}
ImageView image = (ImageView) findViewById(R.id.fullimage);
try
{
image.setImageBitmap(imgFull);
} catch (Exception e) {
// When Error
image.setImageResource(android.R.drawable.ic_menu_report_image);
}
// Show Toast
Toast.makeText(act2.this,imageName,Toast.LENGTH_LONG).show();
}
public ArrayList<HashMap<String, Object>> ConvertJSONtoArrayList(String json) throws JSONException
{
JSONArray data = new JSONArray(resultServer);
ArrayList<HashMap<String, Object>> arr = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, Object>();
map.put("ImageName", (String)c.getString("name"));
map.put("ImagePathThum", (String)c.getString("image"));
map.put("ImagePathFull", (String)c.getString("image_big"));
map.put("description", (String)c.getString("description"));
arr.add(map);
}
return arr;
}
}
public class DownloadFullPhotoFileAsync extends AsyncTask<String, Void, Void> {
String strImageName = "";
String ImageFullPhoto = "";
Bitmap ImageFullBitmap = null;
#Override
protected Void doInBackground(String... params) {
strImageName = MyArrList.get(curPosition).get("ImageName").toString();
ImageFullPhoto = MyArrList.get(curPosition).get("ImagePathFull").toString();
ImageFullBitmap = (Bitmap)loadBitmap(ImageFullPhoto);
return null;
}
}
I'm sorry for long source code but I don't know which part exactly is needed.
I've tried to add in DownloadFullPhotoFileAsync
textDescription = MyArrList.get(curPosition).get("description").toString();
so when is loaded new DownloadFullPhotoFileAsync().execute(); in button next to load also this but I guess this is wrong since it doesn't work.
You can't setText in DoInBackground() function in Async Task, but you can do a setText of your description on PostExecute() which is a function of AsyncTask.
So i think you should try to set your description in PostExecute function in your Asynctask.
take a look at : http://developer.android.com/reference/android/os/AsyncTask.html
I hope this help,
Cheers !
I need to show in a listview a query result to the DB. I'm returning the query 2 values ("cod", "value"). I thought of using a SimpleAdapter to solve the problem, but it did not work.
this is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.techcharacteristic);
PopulateTechCharacteristicList populateList = new PopulateTechCharacteristicList(
this);
populateList.execute();
SimpleAdapter adapter = new SimpleAdapter(this, list,
R.layout.techcharacteristic_rows,
new String[] {"cod", "value"}, new int[] {
R.id.techCharacteristic, R.id.techCharacteristicName });
setListAdapter(adapter);
}
public class PopulateTechCharacteristicList extends
AsyncTask<Integer, String, Integer> {
ProgressDialog progress;
Context context;
public PopulateTechCharacteristicList(Context context) {
this.context = context;
}
protected void onPreExecute() {
progress = ProgressDialog.show(TechCharacteristicList.this,
getResources().getString(R.string.Wait), getResources()
.getString(R.string.LoadingOperations));
}
protected Integer doInBackground(Integer... paramss) {
ArrayList<TechCharacteristic> arrayTechChar = new ArrayList<TechCharacteristic>();
TechCharacteristicWSQueries techCharWSQueries = new TechCharacteristicWSQueries();
try {
arrayTechChar = techCharWSQueries
.selectTechCharacteristicByAsset("ARCH-0026");
HashMap<String, String> temp = new HashMap<String,
for(TechCharacteristic strAux : arrayTechChar)
{
temp.put("cod", strAux.getTechCharacteristic() + " - " + strAux.getTechCharacteristicName());
temp.put("value", strAux.getTechCharacteristicValue());
list.add(temp);
}
} catch (QueryException e) {
e.printStackTrace();
return 0;
}
return 1;
}
protected void onPostExecute(Integer result) {
if(result == 1)
progress.dismiss();
}
}
On account of being utlizando the same codes ("cod", "value") to include values in the HashMap, my listView is always showing the last item inserted. But in my statement SimpleAdapter'm using hard coded ("cod", "value") and whenever I put any value other than ("cod", "value") in the HashMap, the listView carries empty.
Can anyone help me?
On account of being utlizando the same codes ("cod", "value") to
include values in the HashMap, my listView is always showing the
last item inserted.
As you are creating HashMap object out of for loop, and adding values to that object only in the for loop,hence the previous values get erased and you get only last values.
To solve this you need to create the HashMap object in for loop corresponding to each row.
Try
HashMap<String, String> temp = null;
for(TechCharacteristic strAux : arrayTechChar)
{
temp = new HashMap<String,String>();
temp.put("cod", strAux.getTechCharacteristic() + " - " + strAux.getTechCharacteristicName());
temp.put("value", strAux.getTechCharacteristicValue());
list.add(temp);
}
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.