我使用以下代码来捕获对 gridview 项目单元格的单击。这很好用。
grid_main.setAdapter(new ImageAdapter(this));
grid_main.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
}
});
然后我在 gridview 单元格内添加了一个 Spinner 对象。现在,我可以单击 Spinner 对象,但包含的 gridview 单元格不再响应单击。我假设 Spinner 侦听器正在替换 gridview 侦听器。gridview 和 spinner listeners 单独工作都很好,但在一起我有问题。我需要能够同时点击两者。以下是微调器代码:
final Spinner spinner = (Spinner) v.findViewById(R.id.driver_list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(DispatchMonitorCalls.this,
android.R.layout.simple_spinner_item, driverlist_name);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
下面是布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/driverrow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:gravity="left" >
<TextView
android:id="@+id/row_locationtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_alignParentTop="true"
android:text="Empty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/row_timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/row_locationtype"
android:layout_below="@+id/row_locationtype"
android:text="Empty"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/row_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/row_locationtype"
android:layout_below="@+id/row_timestamp"
android:text="Empty"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ff8080" />
<Spinner
android:id="@+id/driver_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/row_locationtype"
android:layout_below="@+id/row_status"
android:paddingBottom="20dp" />
</RelativeLayout>
先感谢您。