单击按钮时ListView中的列表按列表

时间:2014-03-26 08:47:55

标签: android listview

所以我使用ListView从本地数据库填充Custom Adapter。我现在要做的是当我点击一个按钮时,列表视图中的列表将改变其顺序,如图中所示。有人能帮我吗。这是我的代码。

这是当前ListView - > SEE IMAGE

这就是我想要做的事情 - > SEE IMAGE

CustomAdapter.java

public CustomAdaper(Context context,ArrayList<SampleObj> items) {
    super(context,0, items);
    this.context = context;
    this.items = items;
    vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}


@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View v = convertView;
    final ViewHolder holder;
    final SampleObj i = items.get(position);
    if (i != null) {

        final SampleObj ei = (SampleObj)i;

        if (v == null) {
            v = vi.inflate(R.layout.log_row, null);

            holder = new ViewHolder();
            holder.date = (TextView)v.findViewById(R.id.date);
            holder.time = (TextView)v.findViewById(R.id.time);
            holder.buttonID = (TextView)v.findViewById(R.id.buttonID);


            v.setTag(holder);
        } 

        else {
            holder = (ViewHolder)v.getTag();

        }

            holder.date.setText(ei.date);
            holder.time.setText(ei.time);
            holder.buttonID.setText(ei.buttonID);

            }

    return v;
}

private static class ViewHolder {
    public TextView date;
    public TextView time;
    public TextView buttonID;
}

}

1 个答案:

答案 0 :(得分:1)

您需要使用可扩展列表 enter image description here First see this

then this

then this