Note that there are some explanatory texts on larger screens.

plurals
  1. POListView White Screen
    primarykey
    data
    text
    <p>I have a problem with my ListView and I don't know how fix it. I have only a white screen when I launch the activity. Can you help me to fix it please ?</p> <p>Here are the two xml files:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ListView android:id="@+id/listview" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and for the list layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=""/&gt; &lt;TextView android:id="@+id/category" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_marginTop="5dip" android:text=""/&gt; &lt;TextView android:id="@+id/distance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/category" android:layout_alignBottom="@+id/category" android:layout_alignParentRight="true" android:text=""/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The activity:</p> <pre><code>import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import com.actionbarsherlock.app.SherlockActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; public class ProxiRestaurantsListActivity extends SherlockActivity { // Declare Variables ListView list; RestaurantsListAdapter adapter; String[] name; String[] category; String[] distance; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.listview, container, false); // Generate sample data name = new String[] { "Restaurant1", "Restaurant2", "Restaurant3" }; category = new String[] { "Greek Tavern", "Italian", "Fish" }; distance = new String[] { "0.5Km", "1.2Km", "1.9Km" }; // Locate the ListView in listview_main.xml list = (ListView) view.findViewById(R.id.listview); // Pass results to ListViewAdapter Class adapter = new RestaurantsListAdapter(getBaseContext(), name, category, distance); // Binds the Adapter to the ListView list.setAdapter(adapter); // Capture button clicks on ListView items list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // Send single item click data to SingleItemView Class Intent i = new Intent(getBaseContext(), SingleRestaurantViewActivity.class); // Pass all data rank i.putExtra("name", name); // Pass all data country i.putExtra("category", category); // Pass all data population i.putExtra("distance", distance); // Pass a single position i.putExtra("position", position); // Open SingleItemView.java Activity startActivity(i); } }); return view; } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.Settings: Intent i = new Intent(getBaseContext(), SettingsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; default: return super.onOptionsItemSelected(item); } } } </code></pre> <p>and the listview adapter:</p> <pre><code>import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class MuseumListAdapter extends BaseAdapter { // Declare Variables Context context; String[] name; String[] category; String[] distance; LayoutInflater inflater; public MuseumListAdapter(Context context, String[] name, String[] category, String[] distance ) { this.context = context; this.name = name; this.category = category; this.distance = distance; } @Override public int getCount() { return name.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } public View getView(int position, View convertView, ViewGroup parent) { // Declare Variables TextView txtname; TextView txtcategory; TextView txtdistance; inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View itemView = inflater.inflate(R.layout.museumlistlayout, parent, false); // Locate the TextViews in listview_item.xml txtname = (TextView) itemView.findViewById(R.id.name); txtcategory = (TextView) itemView.findViewById(R.id.category); txtdistance = (TextView) itemView.findViewById(R.id.distance); // Capture position and set to the TextViews txtname.setText(name[position]); txtcategory.setText(category[position]); txtdistance.setText(distance[position]); return itemView; } } </code></pre> <p>I hope you have all the relevant information.</p> <p>Thank you very much.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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