Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview,左侧有upvote按钮_Android_Android Layout_Listview_Android Listview_Vote Up Buttons - Fatal编程技术网

Android Listview,左侧有upvote按钮

Android Listview,左侧有upvote按钮,android,android-layout,listview,android-listview,vote-up-buttons,Android,Android Layout,Listview,Android Listview,Vote Up Buttons,我正在尝试制作一个列表,很像reddit中的列表,左侧有一个向上投票按钮,右侧有一些文本(标题、提问用户、数字答案) 我正在尝试创建一个包含以下视图组的列表: 我无法在图片左侧添加Upvote按钮。 每当我在那里添加一个按钮时,我就不能再点击列表项本身(以前如果你点击列表项,它会带你去另一个目的地) 如何创建一个列表,其中列表中的每个项目都可以单击以转到基于该行项目的意图,但列表中的每个行项目都有一个向上投票按钮 以下是我目前的情况: <?xml version="1.0" encodi

我正在尝试制作一个列表,很像reddit中的列表,左侧有一个向上投票按钮,右侧有一些文本(标题、提问用户、数字答案)

我正在尝试创建一个包含以下视图组的列表:

我无法在图片左侧添加Upvote按钮。 每当我在那里添加一个按钮时,我就不能再点击列表项本身(以前如果你点击列表项,它会带你去另一个目的地)

如何创建一个列表,其中列表中的每个项目都可以单击以转到基于该行项目的意图,但列表中的每个行项目都有一个向上投票按钮

以下是我目前的情况:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingTop="2dip"
    android:paddingBottom="2dip"
    >
    <Button
        android:layout_width="16dip"
        android:layout_height="8dip"
        android:layout_marginLeft="12dip"
        android:layout_marginRight="12dip"
        android:layout_marginTop="4dip"
        android:background="@drawable/vote_up_gray"
        android:id="@+id/vote_up_button"/>

    <TextView
        android:layout_width="40dip"
        android:layout_height="32dip"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/vote_up_button"

        android:singleLine="true"
        android:ellipsize="marquee"
        android:gravity="center"
        android:textSize="14sp"
        android:textStyle="bold"
        android:text="0"/>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/Q_list_descriptions">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/title_text_view"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text=""
            android:id="@+id/askedBy_text_view" />

        <TextView
            android:layout_width="fill_parent"
            android:gravity="right"
            android:layout_height="wrap_content"

            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text=""
            android:id="@+id/answers_text_view" />

    </LinearLayout>

</LinearLayout>

</LinearLayout>


改用
RecyclerView
。从来没有这样的问题。您可以为
列表项
中的每个项目指定
OnClickListener
,也可以为适配器中的
列表项
作为一个整体指定
ViewHolder


将android:DegenantFocusability=“BlocksDescents”添加到行的根元素中,然后在设置属性时再试一次android:Focusability=“false”@Blackbelt刚刚尝试过,但当我单击实际行项目时,什么都没有happens@Raj好的,这样做使得点击实际的行项目可以带我去我想去的地方,但是现在人们不能点击向上投票按钮。我点击的任何地方都像我点击了行项目怎么不能点击?请发布ListView实现的代码。我想你是为了这个目的扩展了ListFragment。现在需要做的就是为ListView定义一个自定义适配器。如果您的自定义适配器扩展了ArrayAdapter,那么在重写的getView()方法中,您需要使用findViewById()和setOnclickListener(…)查找按钮的引用。我已经尝试过了,它工作得很好。发布java代码。这似乎有点不对劲。