凌云志轩 2015-05-04 01:43 采纳率: 89%
浏览 1770
已采纳

android gridview子类控件如何由于viewgroup获取焦点

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="afterDescendants" >
            <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/tock_on"
                    android:focusable="false"
                    android:layout_weight="1"
                    android:background="@drawable/tock_on"
                    android:layout_gravity="center_vertical"

afterDescendants:viewgroup 及其子类控件都不能回去焦点
blocksDescendants:viewgroup先获得焦点,选中后子类才能获取焦点。如何让其子类控件先获取焦点呀
Java代码
final GridView dev_list = (GridView) findViewById(R.id.dev_list);
`dev_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final ImageButton tock_on = (ImageButton) dev_list.findViewById(R.id.tock_on);

tock_on.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), "开始说话",Toast.LENGTH_SHORT).show();
tock_on.setBackgroundResource(0);
tock_on.setBackgroundResource(R.drawable.tock_on_btn);
tock_off.setBackgroundResource(0);
tock_off.setBackgroundResource(R.drawable.tock_off_btn);

                }
            });
                            });


  • 写回答

2条回答 默认 最新

  • 凌云志轩 2015-05-04 05:09
    关注

    噢,卖糕点,终于实现了。原来是在gridview里面实现的子控件点击事件。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?