大家好,我是 Android 新手。我正在开发包含 ListAdapter 的应用程序,我想从 onResume 中清除它。
在Activity中是指levelsView。
public class MyActivity extends Activity{
...
@Override
protected void onResume(){
super.onResume();
levelsView.onResume();
}
}
LevelsView 指的是我有 myAdapter 的 FontsSelect
public class FontsSelect extends LinearLayout {
private List<FontLevels> fontsLevels;
public FontsSelect(Context context, AttributeSet attr, int defStyle){
super(context, attr, defStyle);
inflate(context, R.layout.list_view_of_fonts, this);
listViewFonts = (ListView)findViewById(R.id.list_of_fonts);
listViewFonts.setDivider(null);
fontsLevels = new ArrayList<FontLevels>();
levels = new ArrayList<Level>();
createLevels();
myAdapter = new MyAdapter(context);
listViewFonts.setOnItemClickListener(levelSelectListener);
listViewFonts.setAdapter(myAdapter);
}
public void createLevels(){
...
fontsLevels.add(new FontLevels(context, "fonts/TNR.ttf"))}
class MyAdapter extends BaseAdapter {
final LayoutInflater inflater;
public MyAdapter(Context context){
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return fontsLevels.size();
}
@Override
public Object getItem(int position) {
return fontsLevels.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView == null){
convertView = inflater.inflate(R.layout.item_level, parent, false);
holder = new ViewHolder((TextView)convertView.findViewById(R.id.level_name_typeface), (TextView)convertView.findViewById(R.id.level_score_number));
convertView.setTag(holder);
}
else {
holder = (ViewHolder)convertView.getTag();
}
...
return convertView;
}
}
public void onResume(){
listViewFonts.setAdapter(null);
fontsLevels.clear();
fontsLevels.add(new FontLevels(context, "fonts/TNR.ttf");
fontsLevels.add(new FontLevels(context, "fonts/TNR.ttf");
myAdapter = new MyAdapter(getContext(), fontsLevels);
listViewFonts.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
}
这是ckass字体级别
public class FontLevels{
private String fontFullName;
private int _id;
private List<Level> easyLevels;
private List<Level> hardLevels;
public FontLevels(Context context, String fontFullName){
this.fontFullName = fontFullName;
typeface = Typeface.createFromAsset(context.getAssets(), FONTS_DIR + fontFullName);
easyLevels = new ArrayList<Level>(levelNumber);
hardLevels = new ArrayList<Level>(levelNumber);
}
重新启动我的应用程序后,适配器不会更新,并显示旧列表。请帮助))谢谢!