Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid dev: item in listview can not get focus correctly
    primarykey
    data
    text
    <p>I face a listview focus problem. There is a button above the listview(not listview header). And I set listview.setItemsCanFocus to true. When I scroll using trackball, the items in listview can not get focused correctly. I post the layout file and code, hope this helps.</p> <pre><code>package com.gaocx.trackballtest; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView listView = (ListView) findViewById(R.id.listviewId); Button headerBtn = new Button(this); headerBtn.setWidth(LayoutParams.FILL_PARENT); headerBtn.setHeight(LayoutParams.WRAP_CONTENT); headerBtn.setText("ListView Header"); listView.addHeaderView(headerBtn); findViewById(R.id.layoutid1).setFocusable(true); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "Button1", 2000).show(); } }); Button button2 = (Button)findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "Button2", 2000).show(); } }); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1); for (int i = 0; i &lt; 20; ++i) { adapter.add("value" + i); } listView.setAdapter(adapter); listView.setItemsCanFocus(true); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { Toast.makeText(MainActivity.this, "Value" + arg2, 2000).show(); } }); } } </code></pre> <p>The layout file:</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="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/layoutid1"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="@string/hello" /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/hello" android:id="@+id/button1" /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/hello" android:id="@+id/button2" /&gt; &lt;/LinearLayout&gt; &lt;ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/listviewId"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>I think this is a listview bug and post it on android report bug page. But I am rejected, and the android team ask me to post here for help.. So any help would be appreciated. thanks a lot.</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.
 

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