Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing a listview in android
    text
    copied!<p>I have a listview that contains values from webservice.Each page contains only 10 listitems and the next 10 in page 2 etc.Each listitem is clickable and it contains a button which is mainly for voting.So when i click the button in list item 1 ,a value is added to webservice.</p> <p>The button click codes are placed in a custom base adapter class.So that i can easily add the vote.But the problem is,When i submit the vote,i want to refresh my listview also.Suppose if iam in page no 5,refresh that listview page.</p> <p>How can i refresh this listview instantly after submitting the value to webservice?</p> <p>sample code for main.java</p> <pre><code>private class ProgressThreadNextPageLoading extends AsyncTask&lt;String, Void, String&gt; { // private String Content; @Override protected void onPreExecute() { progressDialog = new ProgressDialog(KidsCrackMeUp.this); progressDialog.setMessage("Loading..Please Wait.."); progressDialog.setIcon(R.drawable.icon); progressDialog.show(); } @Override protected String doInBackground(String... urls) { String response = ""; // call ur webservice here try { // pagenum = 1; posts= web .getAllposts(pagenum); response = "Yes"; } catch (Exception e) { e.printStackTrace(); response = "Failure"; } return response; } @Override protected void onPostExecute(String result) { // below line code is to dismiss the progress bar progressDialog.dismiss(); if (posts != null) { adapter = new DynamicListAdapter( main.this, posts lstPosts.setAdapter(adapter); adapter.notifyDataSetChanged(); //btnState.setPressed(true); } </code></pre> <p>----------------------------------custom adapter class</p> <pre><code> viewHolder.btnVoting.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { final Dialog d = new Dialog(activity); d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setContentView(R.layout.voteselectornew); Button btnCategoryCancel = (Button) d .findViewById(R.id.btnCategoryCancel); Button twcVote = (Button) d .findViewById(R.id.btnTwcVote); twcVote.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String confirm = web .addTwcVote(UserSessionKey, Userlist.get(position).contentid); if (confirm.contains("Successfully")) { d.dismiss(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload