Hi:
     I created a view whose layout like:
      TextView    Button    Button
                     ListView
     Everything works fine at touch mode. But weird thing happens when
I try to focus the listview item using trackball. The items in
listView can not be focused. I post my layout file and code, you can
try it on device or emulator.  Is there anyone can help me to figure
out where I am doing wrong?   thanks a lot in advance.

       Here is my xml file:
       <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
        <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:text="@string/hello"
                    />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:text="@string/hello"
                    android:id="@+id/button1"
                    />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:text="@string/hello"
                    android:id="@+id/button2"
                    />
    </LinearLayout>
        <ListView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/listviewId"/>
</LinearLayout>

And my code is below:
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);

        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<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
        for (int i = 0; i < 20; ++i) {
                adapter.add("value" + i);
        }
        listView.setAdapter(adapter);
        listView.setItemsCanFocus(true);
        listView.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> arg0, View arg1, 
int arg2,
                                        long arg3) {
                                Toast.makeText(MainActivity.this, "Value" + 
arg2, 2000).show();
                        }
                });
    }
}

You can t

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to