我有以下布局。我想要实现的是7个水平滚动布局,每个都有一个“ImageView”和一个gridview。当我点击7个网格视图中的每一个时,我希望开始另一个活动。
问题是在7个gridView中的每一个上设置onClickListener都不起作用,从不调用OnItemClickListener。点击没有明显注册。我不确定出了什么问题。我看到一些帖子说点击进入其他一些子项 - ??我不确定哪个子项目。最糟糕的情况我可以在7个imageViews上注册一个点击并采取相应的操作。目前,当gridview为空时,我正在尝试它。即使它显示图像我只想在gridView上发生点击,而不是在任何单独的内容上发生。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/mon"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_mon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/tue"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_tue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/wed"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_wed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/thu"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_thu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/fri"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_fri"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/sat"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_sat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:src="@drawable/sun"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"
/>
<GridView
android:id="@+id/gridview_sun"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
下面给出的点击监听器设置之一
mMonView = (GridView) v.findViewById(R.id.gridview_mon);
try {
setupAdapter(mMonView, mWeekPlanner.getDayList(WeekPlanner.MON));
} catch (InvalidClothesWeekPlannerException e) {
setupAdapter(mMonView, null);
}
mMonView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> gridView, View view,
int pos, long id) {
// Clothes item
// =mWeekPlanner.getDayList(WeekPlanner.MON).get(pos);
Toast.makeText(getActivity(), "YAY gridview clicked!", Toast.LENGTH_SHORT);
Intent intent =new Intent(getActivity(),WeekPagerActivity.class);
intent.putExtra(WeekPlannerFragment.EXTRA_DAY, WeekPlanner.MON);
startActivity(intent);
}
});