android:如何在listview的自定义arrayadapter之后更新项目

时间:2012-11-16 22:24:21

标签: android android-arrayadapter android-view

我自定义了ArrayAdapter,因此它可以返回DataView extends View。对于此DataView,我需要覆盖其onDraw()方法。

在我的new DataView的MainActivity中,我需要更新DataView(即调用onDraw()方法)。我怎么能做到这一点?我应该通过自定义ArrayAdapter还是仅在MainActivity中更新?怎么样?

这是我的自定义ArrayAdapter代码:

public class DataViewAdapter extends ArrayAdapter<DataView>{
Context context;
int layoutResourceId;
ArrayList<DataView> views;


public DataViewAdapter(Context context, int layoutResourceId,
        ArrayList<DataView> views) {
    super(context, layoutResourceId, views);
    this.context = context;
    this.layoutResourceId = layoutResourceId;
    this.views = views;
}

@Override
public View getView(int position, View convertView, ViewGroup parent){
    View row = convertView;
    ViewHolder holder = null;
    if(row == null){
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        holder = new ViewHolder();
        holder.view = (View)row.findViewById(R.id.dataView);
        row.setTag(holder);
    } else {
        holder = (ViewHolder)row.getTag();
    }
    DataView dataView = views.get(position);
    holder.view = dataView;
    return row;
}

static class ViewHolder{
    public View view;
}

}

0 个答案:

没有答案