列表视图中的按钮 [英] buttons within listview

查看:130
本文介绍了列表视图中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有排布置的ListView像

I have listview with row layout like

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" 
    android:weightSum="5"
    >

        <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:id="@+id/ArriveTime"
        android:gravity="center" 
        android:layout_weight="1" />


        <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:id="@+id/Name"
        android:gravity="center" 
        android:layout_weight="1" />

        <Button
        android:focusable="false"

        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:id="@+id/Arrive"
        android:gravity="center" 
        android:layout_weight="1"           
        android:text="Arrive" />

        <Button
        android:focusable="false"

        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:id="@+id/Encounter"
        android:gravity="center" 
        android:layout_weight="1"           
        android:text="Encounter" />

        <Button
         android:focusable="false"

        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:id="@+id/Exit"
        android:gravity="center" 
        android:layout_weight="1"           
        android:text="Exit" />




</LinearLayout>

我要当点击行能够点击的按钮,所以我设置机器人:可聚焦=FALSE并在按我说的

    MainGrid.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {

             Log.d("zzzzzzzzzzzzzzzzzzzzzzzz",""+ oldPosition);

            if(oldPosition != -1)
            {
                MainGrid.getChildAt(oldPosition).setFocusable(false);
                //MainGrid.findViewById(oldPosition).setFocusable(false);
            } 

            // Set the whole list view unfocusable 
             MainGrid.setFocusable(false);


            // focus only on this 
            view.setFocusable(true);

            oldPosition = position -1;

            SetMenueOnClick(position-1) ;
 }});

问题是,在该行第一次点击后,按钮被激活,我不能再次任何想法单击以解决这个问题,我需要激活该行的按钮我点击然后将焦点转移到该行进一步点击

the problem is that after the first click on the row, the buttons be active and I cannot click on it again any idea to fix that , I need to activate the buttons on the row I click then transfer the focus to the row for further click

推荐答案

如果你想同时得到线和按钮可以点击(所有的时间),你并不需要经过所有这些回旋。在该行的xml这两条线只需添加到您的按钮标注:

If you want both the line and the buttons to be clickable (all the time), you don't need to go through all those gyrations. Simply add these two lines to your button callouts in the row xml:

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

然后你只需在您的适配器在活动的每个按钮和项目点击听众,你调用列表为正常设置按钮点击听众。

Then you just set button click listeners in your adapter for each button and item click listeners in the activity where you call the list as normal.

如果您希望禁用,直到你的按钮点击行(我并不清楚,如果这是目标或只是一个后效果你试图去获得这两个可点击的方式),中成立XML是一样尽可能的聚焦的标注,设置按钮为禁用,然后在 onListItemClick 设置一个如果使用一个标志来切换他们点击和点击不使用的语句 button.setEnabled(假); button.setEnabled(真);

If you want the buttons disabled until you click on the row (I wasn't clear if that was the goal or just an after-effect of the way you were trying to go about getting both clickable), the set up in the xml is the same as far as the focusable callouts, set the buttons to disabled and then in the onListItemClick set up an if statement using a flag to toggle them clickable and not clickable by using button.setEnabled(false); and button.setEnabled(true);.

这篇关于列表视图中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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