我在使用API版本23时没有调用我的listview的onItemClick方法。在之前的版本上它运行良好。
我已经阅读了这个问题Issue,似乎可能与此有关。有什么想法吗?
代码很简单,没什么特别的。它适用于API 23以下的所有版本。
列出项目布局:
<TextView
android:id="@+id/history_member_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/history_item_text_size" />
<TextView
android:id="@+id/operator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/history_item_text_size" />
<TextView
android:id="@+id/history_member_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/history_item_text_size" />
<TextView
android:id="@+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text=" = "
android:textSize="@dimen/history_item_text_size" />
<TextView
android:id="@+id/history_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/history_item_text_size" />
列表所在的布局:
<?xml version="1.0" encoding="utf-8"?>
<keyboard.HistoryLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/history_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/history_height"
android:animateLayoutChanges="true"
android:orientation="vertical">
<keyboard.HistoryView
android:id="@+id/history"
android:layout_width="match_parent"
android:layout_height="@dimen/history_height"
android:background="@android:color/white" />
</keyboard.HistoryLayout>
public class HistoryView extends ListView implements AdapterView.OnItemClickListener {
private HistoryAdapter mAdapter;
public HistoryView(Context context) {
super(context);
init();
}
public HistoryView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public HistoryView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mAdapter = new HistoryAdapter();
setOnItemClickListener(this);
setAdapter(mAdapter);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
public void loadHistory() {
ArrayList<CalculationItem> items = CalcManager.getInstance().getHistoryItems();
mAdapter.updateData(items);
}
public void update() {
mAdapter.notifyDataSetChanged();
smoothScrollToPosition(mAdapter.getCount() - 1);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getContext(), "Clicked", Toast.LENGTH_SHORT).show();
}
}