Note that there are some explanatory texts on larger screens.

plurals
  1. PONo data available listview
    text
    copied!<p>I ran into problem with creating listview in my android app.</p> <p>This is my code:</p> <pre><code>public class MainActivity extends ListActivity { private SimpleAdapter emAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set layout as view setContentView(R.layout.main_ui_layout); final Utility utility = new Utility(this); utility.getFiles(); final ListView FileListView = (ListView) findViewById(android.R.id.list); FileListView.setEmptyView(findViewById(R.id.progressBar)); // Create a HashMap for items final ArrayList&lt;HashMap&lt;String, String&gt;&gt; ListItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // we using thread to simulate the download of data Thread emThread = new Thread(new Runnable() { public void run() { // Waiting 3s try { Thread.sleep(2500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Looping through all item nodes &lt;item&gt; for (int em = 0; em &lt; utility.FileMap.size(); em++) { HashMap&lt;String, String&gt; emMap = new HashMap&lt;String, String&gt;(); File Files = new File(utility.FileMap.get("DuroodSharif")); emMap.put(Files.getName(), utility.FileMap.get("DuroodSharif")); ListItems.add(emMap); } } }); // Stop Progress Bar utility.StopProgressBar(); // Adding ListItems to ListView emAdapter = new SimpleAdapter(this, ListItems, R.layout.list_item, new String[] { getString(R.string.TITLE_ID), getString(R.string.DESCRIPTION_ID) }, new int[] { R.id.title, R.id.desciption }); runOnUiThread(new Runnable() { @Override public void run() { // Set List Adapter FileListView.setAdapter(emAdapter); } }); emThread.start(); // Later there's no data Thread myThread = new Thread(new Runnable() { public void run() { // Waiting 3s try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } ListItems.clear(); runOnUiThread(new Runnable() { // Run on the UI Thread to setthe // adapter to the list public void run() { FileListView.setEmptyView(findViewById(R.id.emptyText)); emAdapter.notifyDataSetChanged(); } }); } }); myThread.start(); // Selecting single ListView item ListView emlistView = getListView(); emlistView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // Getting values from selected ListItem String title = ((TextView) view.findViewById(R.id.title)).getText().toString(); String description = ((TextView) view.findViewById(R.id.desciption)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(getString(R.string.TITLE_ID), title); in.putExtra(getString(R.string.DESCRIPTION_ID), description); startActivity(in); } }); } </code></pre> <p>and this is my layout file</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/app_background_portrait_type2" android:orientation="vertical" &gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone" /&gt; &lt;TextView android:id="@+id/emptyText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="No data available" android:visibility="gone" /&gt; </code></pre> <p>'</p> <p>What I am trying to achieve is showing the progress bar till the listview not filled with data the progress bar is displaying continuously. i am adding name of mp3 file from asset folder in my map and then adding that map in to ListItems and till this process is going i am showing a progress bar. </p> <p>Can anybody point me to right direction?</p> <p>Thanks in advance. </p>
 

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