Android app user swipe list, will callback adapter in the GetView method, here can not each item to create a view, so you need to start in the GetView to determine whether the second parameter view is empty.
If it is empty, you need to call the inflate () method to create a new view, and if not empty, use the second parameter view directly.
Well, if an interface has more than two view needs to switch, then the above performance improvement is not the correct way. You need to rewrite the Getitemviewtype method and the Getviewtypecount method in adapter,
This method will be recalled before GetView, and the Android system will return a different view in GetView based on the return value of the Getitemviewtype.
For example: If an interface has an edit mode and a non-editing mode, then the Getviewtypecount method in adapter needs to return 2 directly, indicating that there are two modes, while the Getitemviewtype
It is necessary to judge that the current pattern returns a different itemtype, so that when the GetView callback is used, the view (the second parameter) is based on the different type.
Special Note: The type returned in Getitemviewtype must be counted from 0, otherwise the group will be out of bounds of the exception!
Define two modes
Private final int normal_mode = 0;
Private final int edite_mode = 1;
@Override
public int Getviewtypecount () {
return 2;
}
@Override
public int Getitemviewtype (int position) {
if (Miseditemode) {
return edite_mode;
} else {
return normal_mode;
}
}
@Override
Public View getView (int index, View arg1, ViewGroup arg2) {
View view = null;
int itemType = Getitemviewtype (index);
if (arg1 = = null) {
if (ItemType = = Normal_mode) {
LOG.I ("zzzzzz/////", "non-editing mode is empty");
View = Layoutinflater.from (Mcontext). Inflate (R.layout.list_item_local_info, arg2, false);
} else if (ItemType = = Edite_mode) {
LOG.I ("zzzzzz/////", "edit mode is empty");
View = Layoutinflater.from (Mcontext). Inflate (R.layout.list_item_edite_local_info, arg2, false);
Initviewediteitem (view, E, index);
}
} else {
view = Arg1;
if (ItemType = = Normal_mode) {
LOG.I ("zzzzzz/////", "non-edit mode NOT NULL");
Initviewitem (view, E, index);
} else if (ItemType = = Edite_mode) {
LOG.I ("zzzzzz/////", "edit mode is not empty");
Initviewediteitem (view, E, index);
}
}
return view;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Adapter of Android App performance improvement