动态添加Linearlayout到listviews

时间:2016-01-26 18:07:46

标签: android listview android-adapter

我想通过按下按钮动态地向我的listview添加一个linearlayout。我该怎么办?线性布局包含editText,微调器和标签。这是我的适配器的代码。

public class mBaseAdapter extends BaseAdapter {
ArrayList arrayList = new ArrayList();
LayoutInflater layoutInflater;
Context context;

public mBaseAdapter(Context c, ArrayList a)
{
    this.arrayList = a;
    this.context = c;
}

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

@Override
public Object getItem(int i) {
    return arrayList.get(i);
}

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

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    viewHolder v;
    if(view == null)
    {
        view = layoutInflater.inflate(R.layout.added, viewGroup, false);
        v = new viewHolder(view);
        view.setTag(v);
    }
    else
    {
        v = (viewHolder) view.getTag();
    }

    return view;
}

private class viewHolder {
    TextView text;
    EditText edit1;
    Spinner spin1;

    public viewHolder(View item)
    {
        text = (TextView) item.findViewById(R.id.text1);
        edit1 = (EditText) item.findViewById(R.id.edit);
        spin1 = (Spinner) item.findViewById(R.id.spinner1);
    }

}

}

我正朝着正确的方向前进吗?如何在按钮点击上添加一行?

1 个答案:

答案 0 :(得分:0)

增加listview的模型并根据适配器内的行填充一行。您的行将包含微调器编辑文本和您喜欢的任何内容