我的問題是當我點擊主要佈局中的列表項時,有時會觸發但不是全部時間。 我不知道如何解決這個問題? 請幫助我..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