У меня есть пользовательский ArrayAdapter
и пользовательский макет элемента для Spinner
.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:clickable="true"
android:layout_height="wrap_content">
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:layout_toStartOf="@id/delete"
android:drawablePadding="8dp"
android:gravity="center_vertical|start"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:ellipsize="none"
android:textAppearance="@style/TextAppearance.AppCompat.Menu" />
<ImageButton
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:contentDescription="@null"
android:background="?attr/transparentRoundRipple"
android:src="@drawable/ic_delete_grey600_24px" />
</RelativeLayout>
В этом макете есть кнопка, которая удаляет этот элемент
@Override
public View getDropDownView(int position, View view, ViewGroup parent)
{
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.spinner_user_agent_item, parent, false);
}
TextView textView = view.findViewById(android.R.id.text1);
textView.setText(getItem(position));
ImageButton deleteButton = view.findViewById(R.id.delete);
deleteButton.setOnClickListener((View v) -> removeAgent(getItem(position)));
return view;
}
Но проблема в том, что слушатель этой кнопки блокирует щелчок самого элемента, и я не могу выбрать его из списка. Можно ли изменить поведение и сделать так, чтобы я мог нажать на кнопку (для удаления) и на сам элемент (для выбора)?