安卓:带有可点击电网项目和嵌套视图网格视图(按钮,复选框) [英] Android: Grid view with clickable grid items and nested views (buttons, checkboxes)

查看:112
本文介绍了安卓:带有可点击电网项目和嵌套视图网格视图(按钮,复选框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想实现一个的GridView 其中,项目本身是可以点击的,但在的GridView 是可点击按钮复选框上课。

Basically, I would like to implement a GridView wherein the items themselves are clickable, but within the GridView are clickable Buttons and Checkboxes.

下面是一个示例布局:

Gridview
-----------------------------------------
|[ImageView]        |[ImageView]        |
|[TextView]         |[TextView]         |
|[Button][Checkbox] |[Button][Checkbox] |
-----------------------------------------
|[ImageView]        |[ImageView]        |
|[TextView]         |[TextView]         |
|[Button][Checkbox] |[Button][Checkbox] |
-----------------------------------------

基本上,我想要做的是,当用户点击复选框,多个项目现在可以从的GridView 。当用户点击按钮,A 弹出显示。当用户点击其他地方,新的活动已启动。该整点是不是长期pressing显示上下文菜单,我想一个按钮来取代它。

Basically, what i want to do is, when the user clicks the CheckBox, multiple items can now be selected from the GridView. When the users clicks the Button, A Popup is shown. When the user clicks anywhere else, a new Activity is started. The whole point of this is instead of long-pressing to show the context menu, I would like a button to take its place.

我如何能接近这个场景有什么建议?在我的当前设置,如果我添加了适配器的 GetView()方法中的按钮,只有按钮是可以点击的。整个的GridView 项目无法点击。当我删除按钮的GridView 产品点击一次。看来,这只是整个的GridView 项或按钮是可点击(响应 OnClickListener ()。有没有办法让他们两个可以点击的?

Any suggestions on how I can approach this scenario? In my current setup, if I add the Button within the adapter's GetView() method, only the Button is clickable. The whole GridView item is not clickable. When I remove the Button, the GridView item is clickable again. It seems that it's only the whole GridView Item or the Button is clickable (responds to OnClickListener(). Is there a way to make them both clickable?

推荐答案

这篇文章是老了,但只是参考/谷歌,我有以下解决方案:

This post is old, but just for reference/googlers, I have the following solution:

您需要编写所有的按钮,复选框中只有imageAdapter的getView的事件。 然后在gridview的标签在你layout.xml文件中添加这些行:

You need to write all the events for buttons, checkboxes in getView of the imageAdapter only. Then in your layout.xml file under the gridview tag add these lines:

android:clickable="true"
android:descendantFocusability="beforeDescendants"

和这些行添加到您的按钮,复选框:

and add these lines to your button and checkboxes:

android:focusable="false"
android:focusableInTouchMode="false"

如果你想一些其他的活动开始,如果在GridView项目的任何其他领域被点击/触动你需要使用(标准code)/(你自己的匹配实现):

And if you want some other activity to start if any other area of the gridview item is clicked/touched you would need to use the (standard code)/(your own matching implementation):

GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
        }

干杯,         });

Cheers, });

这篇关于安卓:带有可点击电网项目和嵌套视图网格视图(按钮,复选框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆