setOnItemClickListener

setOnItemClickListener

您好早上好,我认为我无法处理setOnItemClickListener

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

<?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">
                    <TextView
                        android:id="@+id/usernameTv"
                        android:layout_alignParentStart="true"
                        android:layout_width="wrap_content"
                        android:layout_margin="10dp"
                        android:layout_centerVertical="true"
                        android:textSize="@dimen/text_size_Orta"
                        android:textColor="@color/cardview_dark_background"
                        android:layout_height="wrap_content"
                        tools:ignore="PrivateResource" />
                    <Button
                        android:id="@+id/Login_LogOut_Button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minHeight="0dp"
                        android:layout_centerVertical="true"
                        android:layout_alignParentEnd="true"
                        android:layout_marginStart="5dp"
                        android:layout_marginLeft="5dp"
                        android:layout_marginEnd="5dp"
                        android:background="@drawable/logout_rounded"
                        android:drawableRight="@drawable/logout_icon"
                        android:padding="0dp"
                        android:text="@string/Logout_Text_str"
                        android:textColor="@android:color/white"
                        android:textSize="12sp"
                        tools:ignore="RelativeOverlap,RtlHardcoded" />
                </RelativeLayout>
                //in here i cant handled the item click funktşon
                <syr13.comapp4.Custum_Adapters.ExpandableHeightGridView
                    android:id="@+id/Your_Apps_Li"
                    android:numColumns="3"
                    android:layout_below="@id/Your_Apps_Tv"
                    android:horizontalSpacing="6dp"
                    android:layout_margin="5dp"
                    android:verticalSpacing="6dp"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                </syr13.comapp4.Custum_Adapters.ExpandableHeightGridView>

            </RelativeLayout>
        </ScrollView>

    </RelativeLayout>
</FrameLayout>




最佳答案

我认为您可以更改代码




button.setOnItemClickListener(this);





button.setOnClickListener(this);


例如 :-




    public class MainActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button button = findViewById(R.id.button);
            button.setOnClickListener(this);
        }
        @Override
        public void onClick(View v) {
            switch (v.getId())
            {
                case R.id.button:
                    //Do Something
                    break;
            }
        }
    }

关于java - setOnItemClickListener()在Fragment中的ExpandableHeightGridView上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58367902/

10-12 05:31