我的问题是当我点击主要布局中的列表项时,有时会触发但不是全部时间。 我不知道如何解决这个问题? 请帮助我..Android Listview OnClickListener无法正常工作
我的代码是:
View v = convertView.findViewById(R.id.chat_window_single);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("position",v.getTag().toString());
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putLong("eventId", groupEventMoList.get(Integer.parseInt(v.getTag().toString())).getEventId());
editor.putString("eventTitle",groupEventMoList.get(Integer.parseInt(v.getTag().toString())).getText());
editor.commit();
Intent groupAct = new Intent(context, GroupChatActivity.class);
startActivity(groupAct);
}
});
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chat_window_single"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/chat_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="@android:color/primary_text_light"
android:textSize="20sp" >
</TextView>
<TextView
android:id="@+id/event_place"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="@android:color/primary_text_light"
android:textSize="20sp" >
</TextView>
<TextView
android:id="@+id/event_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="@android:color/primary_text_light"
android:textSize="20sp" >
</TextView>
</LinearLayout>
我主要布局文件:
<?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" >
<ListView
android:id="@+id/chat_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="80dp" >
</ListView>
</LinearLayout>
任何帮助,将不胜感激。
你必须使用的,而不是Onclicklistener – Shriram 2015-04-01 06:12:38
onItemClickListener发表您的列表视图中点击lisener代码。并使用linerlayout而不是视图。在getview方法中。 – Shvet 2015-04-01 06:14:29