I have the following, very simple test program for using a ListView. I create a ListView and set it as the content view. I set a ListAdapter which supplies the rows. There are 30 rows, and each row consists of a LinearLayout ViewGroup. Into that ViewGroup, I place a TextView and a Button. When I run the program, I find that I cannot select rows of the list. I can, however, scroll the list and click the button.
If I remove the button from the LinearLayout (so that it contains only the TextView), then I am able to select rows of the list. I would like to be able to have buttons on my individual row views, and still be able to select rows of the list. On another forum, someone said that this was possible, but I am at a loss as to how to accomplish it.
Can anyone give me a clue?
Thanks.
public class ListViewTest extends Activity implements ListAdapter
{
int m_count;
DataSetObserver m_observer;
public ListViewTest()
{
m_count = 30;
m_observer = null;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ListView lv = new ListView(this);
lv.setAdapter(this);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
setContentView(lv);
}
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public boolean isEnabled(int position) {
return true;
}
@Override
public int getCount()
{
return m_count;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getItemViewType(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout vg = new LinearLayout(this);
TextView tv = new TextView(this);
tv.setText("ListItem");
Button bv = new Button(this);
bv.setText("Button");
vg.addView(tv);
vg.addView(bv);
return(vg);
}
@Override
public int getViewTypeCount() {
return 1;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public void registerDataSetObserver(DataSetObserver observer)
{
m_observer = observer;
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
}
}