Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView Issues in Android 2.X
    primarykey
    data
    text
    <p>I have created a Custom Array Adapter to populate the List View and when the Activity Loads the List View text Disappears.</p> <p><strong>PlacesListAdapter.java</strong></p> <pre><code>public class PlacesListAdapter extends ArrayAdapter&lt;Place&gt; implements Filterable { public Context context; private List&lt;Place&gt; places, orig, itemDetailsrrayList; private PlaceFilter filter; public PlacesListAdapter(Context context, int textViewResourceId) { super(context, textViewResourceId); } public PlacesListAdapter(Context context, int resource, List&lt;Place&gt; places) { super(context, resource, places); this.context = context; this.places = places; itemDetailsrrayList = places; orig = new ArrayList&lt;Place&gt;(itemDetailsrrayList); filter = new PlaceFilter(); // imageLoader = new ImageLoader(context.getApplicationContext()); } public int getCount() { return itemDetailsrrayList.size(); } public Place getItem(int position) { return itemDetailsrrayList.get(position); } public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.list_item_place, null); } Place place = places.get(position); if (place != null) { TextView place_name = (TextView) view .findViewById(R.id.place_title); TextView place_distance = (TextView) view .findViewById(R.id.place_distance); ImageView place_category_icon = (ImageView) view .findViewById(R.id.place_category_icon); if (place_name != null) { place_name.setText(place.getPlaceTitle()); } if (place_distance != null) { place_distance.setText("198"); } if (place_category_icon != null) { place_category_icon.setImageResource(R.drawable.icon_category); } } // Setting Alternative Row Colors if (position % 2 == 0) { view.setBackgroundResource(R.drawable.list_view_place_row_1); } else { view.setBackgroundResource(R.drawable.list_view_place_row_2); } return view; } @Override public Filter getFilter() { // TODO Auto-generated method stub return filter; } private class PlaceFilter extends Filter { @Override protected FilterResults performFiltering(CharSequence constraint) { FilterResults oReturn = new FilterResults(); ArrayList&lt;Place&gt; results = new ArrayList&lt;Place&gt;(); if (orig == null) orig = itemDetailsrrayList; if (constraint != null) { if (orig != null &amp;&amp; orig.size() &gt; 0) { for (Place g : orig) { if (g.getPlaceTitle() .toLowerCase() .startsWith(constraint.toString().toLowerCase())) results.add(g); } } oReturn.values = results; } return oReturn; } @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { itemDetailsrrayList = (ArrayList&lt;Place&gt;) results.values; notifyDataSetChanged(); } } } </code></pre> <p><strong>Place.java</strong></p> <pre><code>public class Place { Integer placeId; String placeName = "", placeDistance = "", placeCategoryIcon = ""; public Place(int placeId, String placeName, String placeDistance, String placeCategoryIcon) { this.placeId = placeId; this.placeName = placeName; this.placeDistance = placeDistance; this.placeCategoryIcon = placeCategoryIcon; } public Integer getPlaceId() { return placeId; } public void setPlaceId(int placeId) { this.placeId = placeId; } public String getPlaceName() { return placeName; } public void setPlaceName(String placeName) { this.placeName = placeName; } public String getPlaceDistance() { return placeDistance; } public void setPlaceDistance(String placeDistance) { this.placeDistance = placeDistance; } public String getPlaceCategoryIcon() { return placeCategoryIcon; } public void setPlaceCategoryIcon(String placeCategoryIcon) { this.placeCategoryIcon = placeCategoryIcon; } } </code></pre> <p><strong>MainActivity</strong></p> <pre><code> protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); setContentView(R.layout.activity_main); context = this; Log.i("Nomad", "onCreate"); List&lt;Place&gt; thePlaces = new ArrayList&lt;Place&gt;(); for (int i = 0; i &lt; places.length; i++) { Place pl = new Place(i, places[i], "NO_DISTANCE", "NO_CATEGORYICON"); thePlaces.add(pl); } listView = (ListView) findViewById(R.id.place_list); listView.setEmptyView(findViewById(R.id.empty)); adapter = new PlacesListAdapter(MainActivity.this, thePlaces); listView.setAdapter(adapter); listView.setTextFilterEnabled(true); mSearchView = (SearchView) findViewById(R.id.action_search); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; a, View view, int position, long id) { startActivity(new Intent(MainActivity.this, PlaceActivity.class)); } }); } </code></pre> <p><strong>activity_main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/primary_white" &gt; &lt;ListView android:id="@+id/place_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="#00000000" android:fadingEdge="none" &gt; &lt;/ListView&gt; &lt;TextView android:id="@+id/empty" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="20dp" android:text="@string/list_view_place_empty" android:textColor="@color/black" android:textSize="18sp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>list_item_place.xml</strong></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="fill_parent" android:layout_height="fill_parent" android:paddingBottom="10dp" android:paddingTop="10dp" &gt; &lt;ImageView android:id="@+id/place_category_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:contentDescription="ss" android:paddingLeft="10dp" android:paddingRight="15dp" android:src="@drawable/icon_category" /&gt; &lt;TextView android:id="@+id/place_distance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:paddingRight="15dp" android:textColor="@color/black" android:text="320" /&gt; &lt;TextView android:id="@+id/place_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/place_category_icon" android:ellipsize="end" android:paddingRight="50dp" android:singleLine="true" android:text="Place Name" android:textColor="#191919" android:textSize="18sp" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This is how it appears on Load</p> <p><img src="https://i.stack.imgur.com/aoubt.png" alt="enter image description here"></p> <p>On trying to Scroll the content reappears. <img src="https://i.stack.imgur.com/PAZuC.png" alt="enter image description here"></p>
    singulars
    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.
 

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