出于某种原因,尽管项目显示正常,但单击事件对我的 RecyclerView 不起作用。我根据屏幕尺寸使用了 2 种不同的适配器。有谁知道为什么它不起作用以及如何解决?
recyclerview_item_gridcell(适用于更大的屏幕)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:padding="20dp"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
recyclerview_item_textview(适用于较小的屏幕)
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
/>
活动课
public class MainActivity extends Activity implements MyRecyclerViewAdapterGL.ItemClickListener, MyRecyclerViewAdapterLL.ItemClickListener {
boolean themeState;
MyRecyclerViewAdapterGL adapterGL;
MyRecyclerViewAdapterLL adapterLL;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean isScreenSmall = getResources().getBoolean(R.bool.is_screen_small);
setContentView(R.layout.activity_main);
String[] dataArray = {"Item A", "Item B", "Item C", "Item D" ,"Item E" ,"Item F"};
相关分类