为什么我的Android setOnItemClickListener不起作用?

Mar*_*ton 1 android android-intent android-ui android-layout android-listview

我在设置setOnItemClickListener时遇到问题.以下是我的代码.我已经测试了setAdapter的工作情况,并且在UI上显示了列表和项目.在设置setOnItemClickListener时,它不起作用.

cool_simpleAdapter = new SimpleAdapter(this, items,
    R.layout.mylistitem, new String[] { "title", "link" }, new int[] {
            R.id.textView_title, R.id.textView_link });
cool_listView.setAdapter(cool_simpleAdapter);
Log.d("tag_1", "before setOnItemClickListener");
cool_listView.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
        Log.d("tag_setonItemClick", "in onItemClick");
        Uri uri = Uri.parse("http://www.google.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }
});
Log.d("tag_2", "after setOnItemClickListener");
Run Code Online (Sandbox Code Playgroud)

我把日志跟踪发生了什么:

Log.d("tag_1","before setOnItemClickListener");
Run Code Online (Sandbox Code Playgroud)

Log.d("tag_2","after setOnItemClickListener");
Run Code Online (Sandbox Code Playgroud)

显示但是

Log.d("tag_setonItemClick","in onItemClick");
Run Code Online (Sandbox Code Playgroud)

没有显示.我无法点击该项目,也无法打开URL.我不知道该如何解决这个问题.

编辑:添加mylistitem.xml布局

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/textView_link"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

小智 13

在这种情况下你的Button是聚焦所以listiten setOnItemClickListener没有工作..所以让他们焦点为false ..在xml的Button上添加这一行

android:focusable="false"
Run Code Online (Sandbox Code Playgroud)