1

上下文:我有 2 个类,一个类 Listactivity 和另一个类 AudioListActivity,我已经定义了一个自定义 arrayadapter。因此,在使用 oncreate 的 ListActivity 中,我使用 setListAdapter ( MyListAdapter = new .... ) 调用一次我的自定义 arrayadapter 来用 10 个项目填充我的列表视图。它运作良好。我的问题是,在单击时,在 listactivity 中:1/我调用一个线程来重新加载一个包含 10 个其他项目的数组(效果很好) 2/我想用这个数组刷新我的列表视图(再次没有 setListAdapter,因为我不想在内存中创建另一个适配器对象)。所以我想通知datasetchanged()。但是当我尝试 MyListAdapter 时。“完成”它没有给出通知数据集更改。那我该怎么办?如何通知我的 arrayadapter 刷新列表视图?需要一些帮助 !谢谢你 !

继承人列表活动

 ListView ClassListView;

ListAdapter MyListAdapter;


@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_audio);

    ClassListView = getListView();
    ClassListView.addFooterView(footer);


    //chargement des données de la premiere page de la listview via LA thread
    threadChargeListe(0, "PremierePage", "aucun");


    setListAdapter(MyListAdapter=new AudioListAdapter(this, 0, MyApplication.getMyArrayDonneesListeAudio()));


    //Mise en place des listeners
    addListener();
}
private void addListener() {

    //listener bouton page suivante
    ImageButton MyPageSuivante = (ImageButton) findViewById(R.id.pagesuivante);
    MyPageSuivante.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //chargement des données de la page suivante via LA thread
            int I = MyApplication.getMyArrayDonneesListeAudio().size();
            int idref = MyApplication.getMyArrayDonneesListeAudio().get(I - 1).getIdDemandeAudio();           /* calcul de la ref de l'audio pivot */
            chargeListe(idref, "PageSuivante", "aucun");                                                    
            MyListAdapter.  >>>>> HERE i CAN T ACCESS notifydatasetchanged ???
        }
    });

这是我的数组适配器的第一行

public class AudioListAdapter extends ArrayAdapter<DonneesListeAudio> {


// Variables
private Activity activity;
private ArrayList<DonneesListeAudio> DataOfListView;
private static LayoutInflater Inflater = null;
int classPosition = 0;
ViewWrapper Holder;
private long classTimeHeureLecture = 0;
private AsyncTask<Integer, Void, Void> MyAsynchTask;
private AtomicBoolean isThreadRunnning = new AtomicBoolean();
private AtomicBoolean isThreadPausing = new AtomicBoolean();

String classAudioFileName;


//Constructeur
public AudioListAdapter(Activity activity, int textViewResourceId, ArrayList<DonneesListeAudio> _Liste) {
    super(activity, textViewResourceId, _Liste);
    try {
        this.activity = activity;
        this.DataOfListView = _Liste;

        Inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    } catch (Exception e) {

    }
}




//construction de la vue de l'item
public View getView(int position, View convertView, ViewGroup parent) {
    classPosition = position;
    View ItemView = convertView;

    try {
        if (convertView == null) {  AND SO ON .....
4

1 回答 1

4

ListAdapter has no member notifyDataSetChanged(). You have to cast your MyListAdapter to ArrayAdapter, to access it.

((ArrayAdapter<DonneesListeAudio>) MyListAdapter).notifyDataSetChanged();

check for typo

于 2013-11-10T10:36:45.613 回答