0

vybrations 数组列表中的所有图表都是唯一的,但 getView 正在重复列表的元素。我正确使用了 convertView 但它仍在列表中重复相同的图纸。我不知道我在这里做错了什么?

这是我得到的链接:https ://www.dropbox.com/s/jlt3mr7h5vzb14q/Untitled.jpg

public class AdapterVybrations extends BaseAdapter
{
private Context context;
public ArrayList<Vybration> vybrations;


public AdapterVybrations(Activity context, ArrayList<Vybration> arrayVybrations)
{
    this.context = context;
    this.vybrations = arrayVybrations;
}


@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
    View v = convertView;
    final Vybration vybe = vybrations.get(position);

    if (v == null)
    {
        LayoutInflater vi = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.vybrations_item, null);
    }

    LinearLayout layout = (LinearLayout) v.findViewById(R.id.layoutVybration);
    ImageView play = (ImageView) v.findViewById(R.id.imageViewPlay);

    final ListView lv = (ListView) parent;

    //initialize graph
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setDisplayValues(false);
    renderer.setZoomButtonsVisible(false);
    renderer.setShowGrid(false);
    renderer.setShowAxes(false);
    renderer.setShowLabels(false);
    renderer.setShowLegend(false);
    renderer.setPanEnabled(false);
    renderer.setZoomEnabled(false);
    renderer.setAntialiasing(true);
    renderer.setMargins(new int[] { 10, 10, 10, 10 });
    renderer.setPanEnabled(false, false);
    renderer.setYAxisMax(15);
    renderer.setXAxisMax(100);
    XYSeriesRenderer rendererSeries = new XYSeriesRenderer();
    rendererSeries.setColor(Color.GREEN);
    rendererSeries.setFillPoints(true);
    rendererSeries.setLineWidth(2);
    renderer.addSeriesRenderer(rendererSeries);

    //add data series to graph
    dataset.addSeries(vybe.getGraphSeries());
    GraphicalView graphView = ChartFactory.getTimeChartView(context, dataset, renderer, "Test");

    //add graph to linear layout
    layout.addView(graphView);

    layout.setOnTouchListener(new OnTouchListener()
    {

        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            Log.v("touched", "layout view touched");
            return true;
        }
    });

    play.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            vybe.play(false);
            Log.v("series", vybrations.get(position).getGraphSeriesString());
            Log.v("clickposition", position + "");
        }
    });

    if (lv.getChoiceMode() != ListView.CHOICE_MODE_NONE)
    {
        SparseBooleanArray checked = lv.getCheckedItemPositions();
        if (checked.get(position))
            v.setBackgroundColor(context.getResources().getColor(android.R.color.holo_blue_light));
        else
            v.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
    }

    return v;
}


@Override
public int getCount()
{
    return this.vybrations.size();
}


@Override
public Object getItem(int position)
{
    return this.vybrations.get(position);
}


@Override
public long getItemId(int position)
{
    return position;
}

}
4

1 回答 1

0

已解决:自定义 ListView 项目重复

我确实尝试了 ViewHolder 设计,但没有删除旧视图。holder.linearLayout.removeAllViews()成功了。现在完美运行。

于 2013-02-14T13:48:04.677 回答