我是编程新手,想知道如何调用 onListItemClick()方法:
protected void onListItemClick(ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id)
};
我的问题是,当我们点击调用此方法的列表项时: 它是某种系统回调, 是DVM负责调用它, 或者它是什么?
答案 0 :(得分:3)
我的问题是,当我们点击调用它的列表项时 方法:是某种系统回调,是DVM负责的 调用它,或者它是什么?
ListActivity
执行您在扩展Activity
而不是ListActivity
时所做的工作。它注册了AdapterView.OnItemClickListener
的实例,并且当调用回调方法时,它会调用您要覆盖的方法。
答案 1 :(得分:1)
Android是一个开源平台,因此您可以检查SDK中的所有类,以确定它们的工作方式。
检查AbsListView,它是ListView的父级,您将看到此方法:
@Override
public boolean performItemClick(View view, int position, long id) {
boolean handled = false;
boolean dispatchItemClick = true;
if (mChoiceMode != CHOICE_MODE_NONE) {
handled = true;
boolean checkedStateChanged = false;
if (mChoiceMode == CHOICE_MODE_MULTIPLE ||
(mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode != null)) {
boolean checked = !mCheckStates.get(position, false);
mCheckStates.put(position, checked);
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
if (checked) {
mCheckedIdStates.put(mAdapter.getItemId(position), position);
} else {
mCheckedIdStates.delete(mAdapter.getItemId(position));
}
}
if (checked) {
mCheckedItemCount++;
} else {
mCheckedItemCount--;
}
if (mChoiceActionMode != null) {
mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
position, id, checked);
dispatchItemClick = false;
}
checkedStateChanged = true;
} else if (mChoiceMode == CHOICE_MODE_SINGLE) {
boolean checked = !mCheckStates.get(position, false);
if (checked) {
mCheckStates.clear();
mCheckStates.put(position, true);
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
mCheckedIdStates.clear();
mCheckedIdStates.put(mAdapter.getItemId(position), position);
}
mCheckedItemCount = 1;
} else if (mCheckStates.size() == 0 || !mCheckStates.valueAt(0)) {
mCheckedItemCount = 0;
}
checkedStateChanged = true;
}
if (checkedStateChanged) {
updateOnScreenCheckedViews();
}
}
if (dispatchItemClick) {
handled |= super.performItemClick(view, position, id);
}
return handled;
}
我的问题是,当我们点击调用它的列表项时 方法:是某种系统回调,是DVM负责的 调用它,或者它是什么?
是。这是某种回调。