我的listView不可点击但是当我在模拟器中输入时工作?

时间:2017-05-24 00:42:12

标签: android xml listview

我不知道最新情况如何,但是当我使用手机时,我的列表视图中的自定义适配器项目(一个图像视图和两个文本视图)无法点击。奇怪的是,如果我按下模拟器中的enter键,它会聚焦并点击下一个活动,这是我触摸它时想要做的事情。当我按下物理设备上的列表视图对象时没有任何焦点或任何事情。我是Android开发的新手,我正在使用约束布局和教程我一直在使用相对布局。这是我的代码:

列表类:

 ProductListAdapter adapter = new ProductListAdapter(this, R.layout.content_list,products);

        //hook up listview to adapter
        ListView list = (ListView) findViewById(R.id.listView);
        list.setAdapter(adapter);

        //4. to click on idividual items and pass to details view
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                //make an intent
                Intent intent = new Intent(ListActivity.this,DetailsActivity.class);

                startActivity(intent);

这是我的列表上下文布局中的xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.admin.study2.ListActivity"
    tools:showIn="@layout/activity_list"
    tools:layout_editor_absoluteY="81dp"
    tools:layout_editor_absoluteX="0dp"

    >



    <ListView
        android:id="@+id/listView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"

        app:layout_constraintVertical_bias="1.0"
        tools:choiceMode="singleChoice"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />


    <ImageView
        android:id="@+id/clothImage"
        android:layout_width="87dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        app:layout_constraintBottom_toTopOf="@+id/priceText"
        app:layout_constraintLeft_toLeftOf="@+id/listView"
        app:layout_constraintTop_toTopOf="@+id/listView"
        tools:layout_constraintBottom_creator="1"


        tools:layout_constraintTop_creator="1" />

    <TextView
        android:id="@+id/nameText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="211dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="211dp"
        android:layout_marginTop="31dp"
        android:text=""
        app:layout_constraintLeft_toLeftOf="@+id/listView"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintTop_creator="1"
        android:layout_marginEnd="8dp" />

    <TextView
        android:id="@+id/priceText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="56dp"
        android:text=""
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.69"
        app:layout_constraintLeft_toLeftOf="@+id/listView"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nameText"
        app:layout_constraintVertical_bias="0.0"
        tools:layout_constraintTop_creator="1" />



</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

修复了问题layout_width和layout_height都必须设置为在listview中包装内容。在我之前,他们被设置为零

    

var React = require('react');
var ReactDOM = require('react-dom');
var ReactTagsInput = require('./react-tagsinput.js');

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-with-addons.js"></script>

tags:[];  
var TagsComponent = React.createClass({
    displayName: "TagsComponent",

    getInitialState: function() {
        return {
            tags: ["tag1", "tag2"]
        };
    },

    saveTags: function () {
        console.log("tags: ", this.state.tags.join(", "));
    },

    handleChange: function(value){
        this.setState({tags: value});
    },

    render: function () {
        return 

    <div>
       <ReactTagsInput value={this.state.tags} onChange={this.handleChange}/>   
     </div>;
    }

    });


 module.exports = TagsComponent;