setOnItemClickListener() 不适用于 Fragment 中的

你好,早上好,在我看来,我无法处理 setOnItemClickListener


我正在尝试创建一个在 gridview 中动态列出已安装应用程序的应用程序。我能够以 gridview 形式显示应用程序,但无法使这些项目可单击。当我点击这些项目时什么也没有发生。setOnItemClickListener 内的代码不会在单击事件时触发。


<?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"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".Tab2profile">

    <RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        tools:ignore="UselessParent">

//my scrollview 

        <ScrollView

            android:layout_width="match_parent"

            android:fillViewport="true"

            android:layout_height="match_parent">

            <RelativeLayout

                android:id="@+id/MainRLyout"

                android:layout_width="match_parent"

                android:orientation="vertical"

                android:layout_height="wrap_content">

                <RelativeLayout

                    android:id="@+id/girislayout"

                    android:layout_alignParentTop="true"

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content">

                </RelativeLayout>

                </syr13.comapp4.Custum_Adapters.ExpandableHeightGridView>


            </RelativeLayout>

        </ScrollView>


    </RelativeLayout>

</FrameLayout>



翻过高山走不出你
浏览 93回答 1
1回答

临摹微笑

我认为你可以更改你的代码从button.setOn&nbsp;Item&nbsp;ClickListener(this);到按钮.setOnClickListener(this);例如 :-&nbsp; &nbsp; public class MainActivity extends AppCompatActivity {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; protected void onCreate(Bundle savedInstanceState) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.onCreate(savedInstanceState);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setContentView(R.layout.activity_main);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button button = findViewById(R.id.button);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; button.setOnClickListener(this);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View v) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (v.getId())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case R.id.button:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Do Something&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java