android - 如何多次刷新Android listview?

标签 android android-intent android-listview

  1. 我已经将 arraylist 上的删除操作实现为

    voiceUrl_list.remove(position);
    
  2. 我用过 listvoice.invalidateViews();//导致所有 View 被重建和重绘!

它会刷新 View 并显示一次,但在进一步单击时,应用程序会崩溃。

这是代码!

convertView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {



                    voiceURL=voiceUrl_list.get(position);


                    Log.i("_voice_url_clicked_"," "+voiceURL);  
                    toast = null;
                    try 
                    {
                        player.setDataSource(voiceURL); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source

                        player.prepare(); // you must call this method after setup the datasource in setDataSource method. After calling prepare() the instance of MediaPlayer starts load data from URL to internal buffer.
                    } 
                    catch (Exception e) 
                    {
                        e.printStackTrace();
                    }
                    if(!player.isPlaying())
                    {
                        player.start();
                        Toast.makeText(Call_In_Out.this,"Playing Audio ...",5000).show();

                       Log.i("response is"," uu"+a);


                    }
                    else 
                    {
                        player.pause();

                        Log.e("Pause ***","Inside Else Block***********PAUSE");
                    }   

                    player.setOnCompletionListener(new
                            OnCompletionListener() {

           @Override


 public void onCompletion(MediaPlayer arg0) {

                                              Toast.makeText(getApplicationContext(),"Finished Playing",2000).show();



                                              voiceURL=voiceUrl_list.get(position);



//removing the arraylist entries                                    

                                                voiceUrl_list.remove(position);

                                                listvoice.invalidateViews(); // causes all the views to be rebuilt and redrawn !


                                         }
                                      });

Logcat 中显示的错误:

04-17 07:42:42.898: E/AndroidRuntime(5676): FATAL EXCEPTION: main
04-17 07:42:42.898: E/AndroidRuntime(5676): java.lang.NullPointerException
04-17 07:42:42.898: E/AndroidRuntime(5676):     at com.zoemultiline.call.Call_In_Out$ListVoiceAdapter$1.onClick(Call_In_Out.java:427)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at android.view.View.performClick(View.java:4204)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at android.view.View$PerformClick.run(View.java:17355)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at android.os.Handler.handleCallback(Handler.java:725)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at android.os.Looper.loop(Looper.java:137)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at java.lang.reflect.Method.invokeNative(Native Method)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at java.lang.reflect.Method.invoke(Method.java:511)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-17 07:42:42.898: E/AndroidRuntime(5676):     at dalvik.system.NativeStart.main(Native Method)

最佳答案

只需更新 ListView 中填充的数组或数据,然后调用下面的方法。

YOUR_ADAPTER.notifyDataSetChanged();

希望对你有所帮助。

关于android - 如何多次刷新Android listview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16052820/

相关文章:

android - ListView 中的微调器

android - 动态添加标记时不显示 Google map 工具栏

Android ImageView 显示在模拟器上但不显示在设备上

android - 使用 Youtube Intent 从定义的起点启动视频

java - 将文件从内部存储复制到外部存储

java - 如何在固定时间间隔后刷新listview?

android - 服务不断被破坏

android - UE4 NDK android-19 找不到 'log2'

android - Intent 的 OnDestroy()

android - 最后一个单元格在自定义 Android ListView 布局中不可见