Note that there are some explanatory texts on larger screens.

plurals
  1. POListView header not working as expected?
    primarykey
    data
    text
    <p>In my Android application, I have a class that extends <code>ListActivity</code> and the class itself is a list. (The application is a ToDo list).</p> <p>And I want to add a static header (an image) on top of the list that <i>will scroll</i> with the list. When I use <code>addHeaderView(imageView, null, false)</code> the image is displayed, but it won't work as expected: it will be clickable <i>and</i> perform the action of the first list item. The actual first list item performs the second list items's function, and so on.</p> <p>Any idea why this is and what can I do to resolve it?</p> <p>Here is my code of the <code>onCreate()</code> function:</p> <pre><code>private ListView lv; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); lv = getListView(); ImageView im = new ImageView(this); im.setBackgroundResource(R.drawable.android_robot); lv.addHeaderView(im, null, false); refreshList(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { goToTasks(String.valueOf(getListAdapter().getItem(position))); } }); lv.setCacheColorHint(0); lv.setBackgroundColor(0xFFFFFFFF); registerForContextMenu(lv); int[] colors = {0x00FF9900, 0xAAFFCC00}; lv.setDivider(new GradientDrawable(Orientation.LEFT_RIGHT, colors)); lv.setDividerHeight(2); } </code></pre> <p>And the code for my <code>Adapter</code> (This is in the <code>refreshList()</code> method):</p> <pre><code>ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, populateList()); setListAdapter(adapter); </code></pre> <p>Note: The <code>populateList()</code> method returns an array of <code>String</code>s which is set to the <code>Adapter</code> as in the above code.</p> <p>If any more code or screenshots are needed, ask in the comments.</p> <p>Thanks in advance for any help!</p> <p><b>EDIT:</b></p> <p>I just found a temporary solution: Just adding <code>-1</code> after the <code>position</code> of, </p> <pre><code>goToTasks(String.valueOf(getListAdapter().getItem(position))); </code></pre> <p>will work, but that doesn't answer the real reason why this is happening.</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.
    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