だから私は を持ってExpandableListView
おり、子ビューの中に がありListView
ます。項目の 1 つをクリックすると、別のアクティビティが開きます。この問題は、[戻る] を押して別のリスト項目をクリックすると発生します。それを行うと、前述の例外が発生します。私はビットマップを使用したことがないので、何が問題を引き起こしているのか本当にわかりません。アイテムの再描画が問題なのか、それとも?
キャッシュメカニズムを実装する必要があることを読みました (ref. Caching Bitmaps ) が、開始方法がわかりません。また、ビットマップを使用しない場合、何をキャッシュする必要がありますか? ここで何が欠けていますか?
ログキャット:
09-10 05:48:03.345: E/AndroidRuntime(21011): FATAL EXCEPTION: main
09-10 05:48:03.345: E/AndroidRuntime(21011): java.lang.IllegalArgumentException: Cannot draw recycled bitmaps
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:789)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:118)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:393)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.widget.ImageView.onDraw(ImageView.java:967)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13707)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12645)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12643)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13710)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.widget.FrameLayout.draw(FrameLayout.java:467)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.widget.ScrollView.draw(ScrollView.java:1576)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12645)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13710)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.widget.FrameLayout.draw(FrameLayout.java:467)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.widget.HorizontalScrollView.draw(HorizontalScrollView.java:1562)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12645)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12643)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12643)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12643)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13423)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.draw(View.java:13710)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.widget.FrameLayout.draw(FrameLayout.java:467)
09-10 05:48:03.345: E/AndroidRuntime(21011): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12645)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.View.getDisplayList(View.java:12689)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1198)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2173)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.os.Handler.handleCallback(Handler.java:725)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.os.Handler.dispatchMessage(Handler.java:92)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.os.Looper.loop(Looper.java:137)
09-10 05:48:03.345: E/AndroidRuntime(21011): at android.app.ActivityThread.main(ActivityThread.java:5191)
09-10 05:48:03.345: E/AndroidRuntime(21011): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 05:48:03.345: E/AndroidRuntime(21011): at java.lang.reflect.Method.invoke(Method.java:511)
09-10 05:48:03.345: E/AndroidRuntime(21011): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-10 05:48:03.345: E/AndroidRuntime(21011): a
コード:
私の展開可能なリストアダプター:
public class StaffExpandableListAdapter extends BaseExpandableListAdapter {
private ArrayList<StaffGroup> staffGroups;
private LayoutInflater layoutInflater;
private Resources resource;
private RoomAdapter ra;
private Context context;
public StaffExpandableListAdapter(Context context,
ArrayList<StaffGroup> staffGroups) {
this.staffGroups = staffGroups;
this.layoutInflater = LayoutInflater.from(context);
this.resource = context.getResources();
this.ra = new RoomAdapter(context);
this.context = context;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
StaffChild staffChild = staffGroups.get(groupPosition)
.getStaffDetails();
return staffChild;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final StaffChild staffChildInfo = (StaffChild) getChild(groupPosition,
childPosition);
ViewHolderChild holder;
if (convertView == null) {
convertView = layoutInflater
.inflate(R.layout.child_row_staff, null);
holder = new ViewHolderChild();
holder.contact = (TextView) convertView
.findViewById(R.id.tv_staff_contact);
holder.consultation = (TextView) convertView
.findViewById(R.id.tv_staff_consultation);
holder.locations = (ListView) convertView
.findViewById(R.id.lv_staff_locations);
holder.noRoomLocation = (TextView) convertView.findViewById(R.id.no_room_location);
convertView.setTag(holder);
} else {
holder = (ViewHolderChild) convertView.getTag();
}
holder.contact.setText(staffChildInfo.getContact().trim());
holder.consultation.setText(staffChildInfo.getConsultation().trim());
String roomId = staffChildInfo.getRoomId();
final ArrayList<RoomLocation> roomLocationInfos = new ArrayList<RoomLocation>();
String[] roomIdForSearch = roomId.split(":");
if (roomIdForSearch.length <= 1) {
holder.noRoomLocation.setVisibility(View.VISIBLE);
holder.locations.setVisibility(View.GONE);
}else{
holder.noRoomLocation.setVisibility(View.GONE);
holder.locations.setVisibility(View.VISIBLE);
for (int i = 1; i < roomIdForSearch.length; i++) {
ra.openToRead();
roomLocationInfos.add(ra.getRoomLocation(Integer
.valueOf(roomIdForSearch[i].trim())));
ra.close();
}
String[] items = new String[roomLocationInfos.size()];
int i = 0;
for (RoomLocation rl : roomLocationInfos) {
items[i++] = formatLocationName(rl.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
R.layout.item_location, R.id.tv_item_location, items);
holder.locations.setAdapter(adapter);
adapter.notifyDataSetInvalidated();
adapter.notifyDataSetChanged();
Utility.setListViewHeightBasedOnChildren(holder.locations);
holder.locations.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startBuildnigPlanActivityInSearchMod(
roomLocationInfos.get(position).getX(),
roomLocationInfos.get(position).getY(),
roomLocationInfos.get(position).getBuildingId(),
roomLocationInfos.get(position).getFloorId());
}
});
holder.locations.setFocusable(false);
}
return convertView;
}
@SuppressLint("DefaultLocale")
private String formatLocationName(String locationNumber) {
String location1Format[] = locationNumber.split(":");
String buildingName = location1Format[0].trim();
String roomName = location1Format[1].trim();
return roomName + " (" + buildingName.toUpperCase(Locale.getDefault())
+ ")";
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return staffGroups.get(groupPosition);
}
@Override
public int getGroupCount() {
return staffGroups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
StaffGroup staffGroupInfo = (StaffGroup) getGroup(groupPosition);
ViewHolderGroup holder;
if (convertView == null) {
convertView = layoutInflater
.inflate(R.layout.group_row_staff, null);
holder = new ViewHolderGroup();
holder.staffId = (TextView) convertView
.findViewById(R.id.tv_staff_id);
holder.staffName = (TextView) convertView
.findViewById(R.id.tv_staff_name);
holder.groupIndicator = (ImageView) convertView
.findViewById(R.id.iv_group_indicator);
convertView.setTag(holder);
} else {
holder = (ViewHolderGroup) convertView.getTag();
}
if (isExpanded) {
holder.groupIndicator.setImageDrawable(resource
.getDrawable(R.drawable.iv_expanded));
} else {
holder.groupIndicator.setImageDrawable(resource
.getDrawable(R.drawable.iv_not_expanded));
}
holder.staffId.setText(staffGroupInfo.getId().trim());
if (staffGroupInfo.getTitle().trim().equals("No data")) {
holder.staffName.setText(staffGroupInfo.getStaffName().trim());
} else {
holder.staffName.setText(staffGroupInfo.getStaffName().trim()
+ ", " + staffGroupInfo.getTitle().trim());
}
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void startBuildnigPlanActivityInSearchMod(){
...
}
/**
* ViewHolderGroup class for group view
*
*
*
*/
static class ViewHolderGroup {
TextView staffId;
TextView staffName;
ImageView groupIndicator;
}
/**
* ViewHolderChild class for child view
*
*
*
*/
static class ViewHolderChild {
ListView locations;
TextView contact;
TextView consultation;
TextView noRoomLocation;
}
}
はのListView
内部で作成され、 も作成されgetChildView
ますsetOnItemClickListener
。私のアクティビティでは、通常ExpandableListView
. お役に立てれば?!