ExpandableListView はほとんど空です。何がそんなに多くのメモリを浪費しているのか、私にはよくわかりません。重いスクロール (上下に約 60 回) の後、アプリが応答を停止します。いくつかの調査を行ったところ、このエラーは targetSdkVersions 8 から 13 でのみ発生することがわかりました。バージョン 14 以降ではすべて問題ありません。私のアプリは、Android サポート ライブラリ v4 と ViewPager の ViewPagerIndicator を使用します。これは厄介なバグですか、それとも私のコードに何か問題がありますか?
package com.test.test;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import com.viewpagerindicator.TabPageIndicator;
public class MainActivity extends Activity{
public ExpandableListAdapter mAdapter;
final String[] page_titles = new String[]{"page1","page2"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//Instantiating the adapter
myAdapter mAdapter = new myAdapter(this);
//instantiate the Views
ViewPager mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
TabPageIndicator mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
private class myAdapter extends PagerAdapter{
Context context;
public myAdapter(Context c){
this.context = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return page_titles.length;
}
@Override
public boolean isViewFromObject(View v, Object o) {
// TODO Auto-generated method stub
return v.equals(o);
}
public CharSequence getPageTitle(int position) {
return page_titles[position];
}
public Object instantiateItem(View pager, int position) {
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.expander, null, false);
ExpandableListView elv1 = (ExpandableListView) v.findViewById(R.id.elv1);
MainActivity.this.mAdapter = new BaseExpandableListAdapter() {
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = inflater.inflate(R.layout.childview, null, false);
return v;
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public int getGroupCount() {
return 20;
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = inflater.inflate(R.layout.twolinelistitem, parent, false);
return v;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
};
elv1.setAdapter(MainActivity.this.mAdapter);
((ViewPager) pager).addView(v, 0);
return v;
}
@Override
public void destroyItem(View pager, int position, Object view) {
((ViewPager) pager).removeView((View) view);
}
@Override
public void finishUpdate(View view) {
}
@Override
public void restoreState(Parcelable p, ClassLoader c) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View view) {
}
}
}