Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Listview in from other fragment
    primarykey
    data
    text
    <p>I am using the tutorial on <a href="http://manishkpr.webheavens.com/android-viewpager-example/" rel="nofollow">Manishkpr</a> to create a app where you swipe between 1) layoutOne: here you create a file and 2) layoutTwo: shows a listview of all created files in a certain folder.</p> <p>Problem: if you create a file, it is not immediately shown in the listview. I found that I should use this code in my LayoutOne.java:</p> <pre><code> LayoutTwo fragment = (LayoutTwo) getFragmentManager().findFragmentByTag("TESTTWO"); fragment.getAdapter().notifyDataSetChanged(); </code></pre> <p>In LayoutTwo.java I added: </p> <pre><code>private static final String TAG = "TESTTWO"; //and the function getAdapter: public CustomArrayAdapter getAdapter() { return adapter; } </code></pre> <p>However, I am getting a nullpointer exception on <code>fragment.getAdapter().notifyDataSetChanged();</code>. How can I solve this, and is this the best way actually?</p> <p><strong>EDIT</strong></p> <pre><code>myList = new ArrayList&lt;RecordedFile&gt;(); File directory = Environment.getExternalStorageDirectory(); file = new File(directory + "/test/"); File list[] = file.listFiles(); for (int i = 0; i &lt; list.length; i++) { if (checkExtension(list[i].getName()) == true) { RecordedFile q = new RecordedFile(); q.setTitle(list[i].getName()); q.setFileSize(readableFileSize(list[i].length())); myList.add(q); } } adapter = new CustomArrayAdapter(myContext, R.layout.listview_item_row, myList); listView.setAdapter(adapter); </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