简体   繁体   English

要更新或刷新列表视图

[英]Want to update or refresh listview

I have listview which is looking like below 我有如下的listview

在此处输入图片说明

it is one kind of Radio based application 这是一种基于无线电的应用程序

in that when user tap on image AsyncTask will be called and Music will be played and getting some information which will be replaced with AMIT SIDDHPURA text 因为当用户点击图像时,将调用AsyncTask并播放音乐并获取一些信息,这些信息将被替换为AMIT SIDDHPURA文本

below is my code 下面是我的代码

    holder.imgPlay.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    new MetadataTask2().execute(holder.txtMetadata);



                            }

    class StreamHolder {
        TextView txtStreamName;
        TextView txtStream;
        TextView txtMetadata;
        ImageView imgPlay;
    }

And MetaDataTask2 class code is below 而且MetaDataTask2类代码如下

   class MetadataTask2 extends AsyncTask<TextView, Void, IcyStreamMeta> {
    String title_artist;
    TextView txtView;

    @Override
    protected com.example.xmlparsingex.IcyStreamMeta doInBackground(TextView... arg0) {
        txtView = arg0[0];

        return streamMeta;
    }

    @Override
    protected void onPostExecute(IcyStreamMeta result) {
        try {
            txtView.setText("Hiiiiiiiiiii............");
            MCObjectMetadata.cancel();
            MCObjectMetadata = new MyCounterMetadata(10000, 1000);
            MCObjectMetadata.start();

            **adapter.notifyDataSetChanged();
            mainListView.setAdapter(adapter);
            mainListView.invalidate();**

            startService(new Intent(CompaniesList.this, NotifyService.class));

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        try {
            PD = ProgressDialog.show(CompaniesList.this, "Tuning...", "Please Wait...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

but the problem is that listview is not updating means the orange text which is displaying in listview is not replacing with Hiiiiiii 但是问题是列表视图没有更新,这意味着列表视图中显示的橙色文本没有替换为Hiiiiiii

如果它是一个ListView,我希望在Adapter的getView()方法中更改textview……或者如果列表是由游标支持的,则在bindView()中.....虽然我不确定您的方法。

You actually need to recreate your adapter instead of calling notifyDataSetChanged() . 实际上,您实际上需要重新创建适配器,而不是调用notifyDataSetChanged() See this previous SO answer for an explanation. 请参阅此先前的SO答案以获取解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM