Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove a specific row from listview?
    primarykey
    data
    text
    <p>I'm trying to remove a specific row from listview, but my app keeps crashing.</p> <p>First, I tried removing item form listAdapter only, but it crashes:</p> <pre><code>listAdapter.remove(listAdapter.getItem(toDelete)); listAdapter.notifyDataSetChanged(); </code></pre> <p>Then I also tried removing it from listView directly but it also crashes:</p> <pre><code>listView.removeViewAt(toDelete); listAdapter.notifyDataSetChanged(); </code></pre> <p>toDelete is an integer variable that has a number id of the row that I'm clicking.</p> <p>So how could I delete a specific row from listview?</p> <p>This is the full code, if anyone wants it:</p> <pre><code>listView.setOnItemLongClickListener(new OnItemLongClickListener(){ @Override public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { deleteAlert.setTitle("Warning"); deleteAlert.setMessage("Are you sure you want to delete this?"); toDelete = arg2; deleteAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { File directory = new File (externalStoragePath + File.separator + "Android/data/com.whizzappseasyvoicenotepad/"); File deleteFile = new File (directory, fileNames.get(toDelete) + ".mp3"); deleteFile.delete(); dialog.dismiss(); listView.removeViewAt(toDelete); listAdapter.notifyDataSetChanged(); Log.i("TAG", "Deleting file: " + directory + fileNames.get(toDelete) + ".mp3"); } }); </code></pre> <p>It's really hard to expand the "it crashes" part. It's simple: as soon as I click the "yes" button, the app crashes. Here's the logcat file if it helps:</p> <pre><code>08-06 19:05:07.437: E/AndroidRuntime(16257): FATAL EXCEPTION: main 08-06 19:05:07.437: E/AndroidRuntime(16257): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 08-06 19:05:07.437: E/AndroidRuntime(16257): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) 08-06 19:05:07.437: E/AndroidRuntime(16257): at java.util.ArrayList.get(ArrayList.java:308) 08-06 19:05:07.437: E/AndroidRuntime(16257): at com.whizzappseasyvoicenotepad.RecordedLibrary$2$1.onClick(RecordedLibrary.java:113) 08-06 19:05:07.437: E/AndroidRuntime(16257): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166) 08-06 19:05:07.437: E/AndroidRuntime(16257): at android.os.Handler.dispatchMessage(Handler.java:99) 08-06 19:05:07.437: E/AndroidRuntime(16257): at android.os.Looper.loop(Looper.java:137) 08-06 19:05:07.437: E/AndroidRuntime(16257): at android.app.ActivityThread.main(ActivityThread.java:5103) 08-06 19:05:07.437: E/AndroidRuntime(16257): at java.lang.reflect.Method.invokeNative(Native Method) 08-06 19:05:07.437: E/AndroidRuntime(16257): at java.lang.reflect.Method.invoke(Method.java:525) 08-06 19:05:07.437: E/AndroidRuntime(16257): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 08-06 19:05:07.437: E/AndroidRuntime(16257): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 08-06 19:05:07.437: E/AndroidRuntime(16257): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload