Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your adapter add:</p> <pre><code>public void setTitle(String[] title) { this.title = title; } public void setDate(String[] date) { this.date = date; } public void setImagepath(String[] imagepath) { this.imagepath = imagepath; } </code></pre> <p>When the more button is pressed call the three methods above with arrays containing 20 objects. Then call <code>notifyDataSetChanged</code> on your adapter.</p> <p><strong>Update:</strong></p> <p>This is working for me: Activity:</p> <pre><code>public class HelpProjectActivity extends Activity { private ArrayList&lt;Item&gt; items; private boolean extend = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); createArray(); ListView lv = (ListView)findViewById(R.id.list); lv.setAdapter(new HelpListAdapter()); } private void createArray() { items = new ArrayList&lt;Item&gt;(); for(int i = 0; i &lt; 20; i++) { Item item = new Item(); item.title = "Title " + i; item.subtitle = "Subtitle " + i; item.image = "default"; items.add(item); } } public void morePressed(View v) { extend = !extend; Button b = (Button) findViewById(R.id.button); b.setText(extend ? R.string.less_button : R.string.more_button); ListView lv = (ListView)findViewById(R.id.list); ((BaseAdapter)lv.getAdapter()).notifyDataSetChanged(); } private class HelpListAdapter extends BaseAdapter { @Override public int getCount() { if (extend) { return items.size(); } return items.size()/2; } @Override public Object getItem(int pos) { return items.get(pos); } @Override public long getItemId(int pos) { return pos; } @Override public View getView(int pos, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { v = View.inflate(getApplicationContext(), R.layout.litst_item, null); } Item item = items.get(pos); TextView titleText = (TextView) v.findViewById(R.id.list_item_title); titleText.setText(item.title); TextView subtitleText = (TextView) v.findViewById(R.id.list_item_subtitle); subtitleText.setText(item.subtitle); ImageView image = (ImageView) v.findViewById(R.id.list_image); if (item.image.equalsIgnoreCase("default")) { image.setImageResource(R.drawable.default_list_image); } else { // what ever } return v; } } } </code></pre> <p>main.xml:</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:orientation="vertical" &gt; &lt;Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="10dp" android:onClick="morePressed" android:text="@string/more_button" /&gt; &lt;ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>list_item.xml:</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="wrap_content" android:orientation="horizontal" &gt; &lt;ImageView android:id="@+id/list_image" android:layout_width="40dp" android:layout_height="40dp" android:layout_margin="5dp" android:layout_gravity="center_vertical" android:contentDescription="@string/list_image" /&gt; &lt;LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/list_item_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" /&gt; &lt;TextView android:id="@+id/list_item_subtitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="italic" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Item.java:</p> <pre><code>public class Item { String image; String title; String subtitle; } </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.
    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