Listview在android中的奇怪行为

时间:2013-02-01 05:51:46

标签: android android-layout listview android-listview

main.xml文件是:

<ListView
    android:id="@+id/listViewMovies"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:cacheColorHint="@android:color/transparent"
    android:divider="#0EBDFE"
    android:dividerHeight="2dp"
    android:fadingEdge="none" />

这是listview的onclick事件:

listViewMovies.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View view, int pos,
                long arg3) {
        // TODO Auto-generated method stub
        Log.i("MainActivity", "clicked position: " + pos);
        Intent intent = new Intent(getApplicationContext(),
                    MovieDetailsActivity.class);
        intent.putExtra("id", arrayIds.get(pos));
        intent.putExtra("name", arrayTitles.get(pos));
        intent.putExtra("release_date", arrayReleaseDate.get(pos));
        intent.putExtra("casts", arrayAbridgedCast.get(pos));
        intent.putExtra("critics_consensus",
                    arrayCriticsConsensus.get(pos));
        intent.putExtra("synopsis", arraySynopsis.get(pos));
        intent.putExtra("trailor", arrayLinks.get(pos));
        intent.putExtra("thumb_img", arrayThumbPosters.get(pos));
        intent.putExtra("profile_img", arrayProfilePosters.get(pos));
            startActivity(intent);
    }
});

但有时会调用click事件,但有时却不会。

任何人都可以建议我应该解决这个问题吗?

1 个答案:

答案 0 :(得分:-1)

您是否为任何包含列表项按钮的xml文件进行了充气。如果是,则按钮会阻止列表项上的单击事件。要解决这个问题,您可以添加

<Button
   android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

希望它会帮助你..