凌云志轩 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条)

报告相同问题?

悬赏问题

  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题