Hi, I have a working ListActivity class. Each of the list item consists of an ImageView and a TextView.
However, when I try to replace the ImageView with ImageButton, The list becomes unselectable. The onListItemClick or any other function no longer get called when press a list item (Although the track ball can still focus a list item, but nothing more can be done). I have searched the forum and also the internet and failed to find any such working example, apart from one guy reporting a similar problem but with no answer. The following is my code: 1. The list_item.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"> <ImageButton android:id="@+id/refresh" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:src="@drawable/refresh" /> <TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toRightOf="@id/refresh" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:singleLine="true"/> </RelativeLayout> 2. the Main ListActivity class: import android.app.Dialog; import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class TestListActivity extends ListActivity implements Constants { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new EfficientAdapter(this)); } @Override protected void onListItemClick(ListView l, View v, int index, long id) { Log.i("", "onListitemClick"); } public boolean onContextItemSelected(MenuItem item) { Log.i("", "onContextItemSelected"); return false; } private class EfficientAdapter extends BaseAdapter implements Constants { private LayoutInflater layoutInflater; Context ctx; public EfficientAdapter(Context context) { // Cache the LayoutInflate to avoid asking for a new one each time. layoutInflater = LayoutInflater.from(context); ctx = context; } @Override public int getCount() { Log.i("", "getCount"); return SIZE; } @Override public Object getItem(int position) { Log.i("", "getItem"); return "TBD"; } @Override public long getItemId(int positin) { Log.i("", "getItemId"); return positin; } public void update(int position) { notifyDataSetChanged(); // triggers the view data to be refreshed! } /** * Make a view to hold each list item */ @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i("", "getView"); ViewHolder holder; if (convertView == null) { convertView = this.layoutInflater.inflate(R.layout.list_item, parent, false); holder = new ViewHolder(); holder.title = (TextView) convertView.findViewById(R.id.title); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.title.setText(R.string.title); parent.focusableViewAvailable(convertView); // originally without this. Added for testing, still not working! return convertView; } private class ViewHolder { //ImageButton imageButton; TextView title; } } } Is there any way to make ListActivity working with ImageButton or this actually can not be achieved (iPhone can this)? Any help would be most appreciated. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en