2012-01-16 16 views
0

webserviceからの値を含むlistviewがあります。各ページには10個のlistitemと次の10個のページがあります。各listitemはクリック可能で、主に投票用のボタンが含まれています。リスト項目1のボタンをクリックすると、Webサービスに値が追加されます。androidのリストビューをリフレッシュする

ボタンのクリックコードは、カスタムベースアダプタクラスに配置されています。私は簡単にvote.Butを追加することができますので、私は投票を提出すると、私もリストビューを更新したいです。いいえ、リストビューのページをリフレッシュしてください。

webserviceに値を送信した後、このリストビューを直ちに更新できますか? main.java

private class ProgressThreadNextPageLoading extends 
AsyncTask<String, Void, String> { 

    // 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); 
     } 

ため

サンプルコード--------------------------------- -customアダプタクラス

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(); 

} 
+0

[Androidリストビューの更新](http://stackoverflow.com/questions/4088862/android-list-view-refresh)の複製が可能 –

答えて

3

として変更を更新するために、あなたのリストビューアダプタのメソッドを呼び出す:あなたはデータが変更されたあなたのListViewアダプタを通知する必要が

adapter.notifyDataSetChanged(); 
+0

これはどのような条件をチェックするべきですか? –

+0

投票操作が完了したら、アダプタクラスで使用されているデータを更新し、アダプタのnotifyDataSetChangedを呼び出してリスト内のビューを自動的に更新してください – waqaslam

+0

申し訳ありませんが、リストビューは、activity.Soの開始時にロードされ、これを通知する場所を知らない。 –

3

listViewAdapater.notifyDataSetChanged(); 

あなたは、更新された配列でコンストラクタを使用してアダプタを復元することができます。

関連する問題