Wednesday, 15 September 2010

ListView Adapter issue in android -


My code is for browsing through all the folders in the device. I

  private File file; Private listing & lt; String & gt; DirectoriesList; See the list of private list views; Private array adapter & lt; String & gt; Adapter; Crate on Public Zero (Bundle Saved Instantstate) {Super. Secret (Saved Instantstate); SetContentView (R.layout.folder_browse_screen); ListView = (ListView) findViewById (R.id.foldersListView); Directories = New Arrestists & lt; String & gt; (); File = new file ("/ mnt"); File list [] = file.listFiles (); If (list! = Null & amp; list.length & gt; = 1) {for (int i = 0; i & lt; list.length; i ++) {file f = list [i]; If (! F.isHidden () & amp; amp; amp; F. CanRead () & amp; amp; amp;; F Dysentery ()) {directoriesList.add (f.getName ()); }} Adapter = New Arrayadapter & lt; String & gt; (This, R.Let.List_RO, RID.folder, name directories); ListView.setAdapter (adapter); }   

OnItemClick:

  @Override IteemClick on Public Zero (adapter view & lt;? & Gt; arg0, see arg1, int position, long arg3 ) {Try {file temp_file = new file (file, directory list, status (status)); If (! Temp_file.isHidden () & amp; amp; amp; temp_file.canRead () & amp; amp; amp; temp_file.isDirectory ()) {file = new file (file, directory; list status (Event)); File list [] = file.listFiles (); DirectoriesList.clear (); If (list! = Null & amp; list.length & gt; = 1) {for (int i = 0; i & lt; list.length; i ++) {file f = list [i]; If (! F.isHidden () & amp; amp; amp; F. CanRead () & amp; amp; amp;; F Dysentery ()) {directoriesList.add (f.getName ()); }} Adapter.notifyDataSetChanged (); }}} Hold (exception e) {e.printStackTrace (); }}   

Exception: java.lang.IllegalStateException: The content of the adapter has changed, but the notification to ListView was not received. Make sure that the content of your adapter has not been modified from the background thread, but only from the UI thread. [See in the list (2131034114, class android.widget.ListView) with adapter (class android.widget.ArrayAdapter)]

Where am'i thread is using? Why is the force closed on the click of any empty folder? Please help me

I believe that the problem is that onClick handler, you always clear () list, but Then only inform the adapter if the selected directory is not empty.

Therefore, when an empty directory is clicked, the list changes (clear), but the adapter is not notified.

Therefore error message, "The content of the adapter has changed, but ListView did not receive a notification".

Ignore Threads of Goods - This error is just an estimate by the author, the message is not a sure sign that you have modified the UI from the background thread.

No comments:

Post a Comment