views:

80

answers:

0

hello, i have a problem with notifyDataSetChanged()

the data source (mData) has been changed, but the list did not change itself .

i need your help. thx!

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

setContentView(R.layout.fairlist); mData = getData();

SimpleAdapter adapter = new SimpleAdapter(this, mData, R.layout.imglist, new String[] { "messe_title", "messe_date", "messe_logo_s" }, new int[] { R.id.messe_title, R.id.messe_date, R.id.messe_logo_s });

adapter.setViewBinder(new GcViewBinder());

this.setListAdapter(adapter);

View updateButton = findViewById(R.id.update_btn);

updateButton.setOnClickListener(this);

}

@Override public void onClick(View v) { ConnectivityManager nw = (ConnectivityManager) FairListActivity.this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netinfo = nw.getActiveNetworkInfo();

if (netinfo.isAvailable() && netinfo.isConnected()) { updatedownload(); } else { alertNonet(); } }

private void updatedownload() { ...

    handler = new Handler() {
     @Override
     public void handleMessage(Message msg) {
      switch (msg.what) {
      case UPDATE_UI: {
       isUpdate = true;
       SimpleAdapter adapter = (SimpleAdapter) FairListActivity.this
         .getListAdapter();
       mData = null;
       mData = getData(); 

       adapter.notifyDataSetChanged();

       break;
      }
      default:
       break;
      }

     }

    };

    // Thread t = new Thread(new Runnable()
    handler.post(new Runnable() {

     @Override
     public void run() {

     ...
     ...
       pDialog.dismiss();

       handler.sendEmptyMessageDelayed(
         UPDATE_UI, 0);

      } else {

       alertTimeout();

      }
     }

    });


   }
  }).setNegativeButton(R.string.no,
  new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog,
     int whichButton) {
    dialog.dismiss();
   }
  }).create();

dialog.show();

}

related questions