Я знаю, что есть несколько андерсеров на этот вопрос, но никто не работал в моем случае. Я пытаюсь сделать ListView с помощью настраиваемого адаптера в фрагменте, и элементы не будут доступны для кликов. Это мой OnItemClickListener:ListViewItem не доступен для скачивания в Фрагмент
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("Klick", "Klick");
HeroItem heroItem = (HeroItem) heroSelect.getItemAtPosition(i);
int id = heroItem.id;
FragmentManager fragmentManager = getFragmentManager();
Fragment fragment = HeroDetailFragment.newInstance(String.valueOf(id));
fragmentManager.beginTransaction().replace(R.id.content_selecthero, fragment, null).addToBackStack(null).commit();
}
OnItemClickListener устанавливается в OnViewCreated так:
heroSelect.setClickable(true);
heroSelect.setAdapter(new HeroSelectAdapter(getContext(),array));
heroSelect.setOnItemClickListener(this);
Вот XML для Items:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:descendantFocusability="blocksDescendants">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/itemList"
android:descendantFocusability="blocksDescendants">
<ImageView
android:layout_height="60dp"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/heroselect_avatar"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:scaleType="fitCenter"
android:layout_width="60dp"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"/>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/heroselect_avatar"
android:layout_toEndOf="@+id/heroselect_avatar"
android:layout_marginLeft="65dp"
android:layout_marginStart="65dp"
android:id="@+id/heroselect_name"
android:textColor="@color/colorWhite"
android:textSize="30sp"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout>
</FrameLayout>
И один за фрагмент :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.rocketfox.overwatchinfo.HeroSelectFragment"
android:background="@color/colorPrimary"
android:id="@+id/content_selecthero">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_view_heroes" />
Щелчок по элементу просто не запускает ничего, и после нескольких часов попыток исправить это я решил рассказать вам все! Заранее спасибо :)
удалите эту строку кода heroSelect.setClickable (true); и проверить. –
ничего себе, что сработало ... спасибо! –