Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you are using default layout android.R.layout.simple_list_item_1 for listview item. instead create one layout with textview with single line enable. and pass it to listview. and use custom array adapter for listview.</p> <p>Do like this: create list itemview XML <strong>listview_item_row.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:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp"&gt; &lt;TextView android:id="@+id/txtTitle" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:textStyle="bold" android:textSize="22dp" android:textColor="#000000" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>One class like </p> <p><strong>Weather.java</strong></p> <pre><code>public class Weather { public String title; public Weather(){ super(); } public Weather(String title) { super(); this.title = title; } } </code></pre> <p>and then create array adapter class </p> <pre><code>public class WeatherAdapter extends ArrayAdapter&lt;Weather&gt;{ Context context; int layoutResourceId; Weather data[] = null; public WeatherAdapter(Context context, int layoutResourceId, Weather[] data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; WeatherHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new WeatherHolder(); holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle); row.setTag(holder); } else { holder = (WeatherHolder)row.getTag(); } Weather weather = data[position]; holder.txtTitle.setText(weather.title); return row; } static class WeatherHolder { TextView txtTitle; } } </code></pre> <p>And use like this in your activity:</p> <pre><code>Weather weather_data[] = new Weather[] { new Weather("Cloudy"), new Weather("Showers"), new Weather("Snow"), new Weather("Storm"), new Weather("Sunny") }; WeatherAdapter adapter = new WeatherAdapter(this, R.layout.listview_item_row, weather_data); listView1.setAdapter(adapter); </code></pre> <p>Hope it Helps!!!</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