效果图:
参考:https://github.com/Aspsine/EditTextInListView 非常感谢
如果只是ListView里面只包含一套布局的话,可以参考这里:http://blog.csdn.net/fan7983377/article/details/51516155
这个效果的主要问题地方就是多套item和每个item内部的EditText数据由于listview的复用导致数据混乱问题:
主要代码就是adapter里面的:
public class AddAdapter extends BaseAdapter {
private Context context;
private List<AddBean> mans;
private LayoutInflater layinf;
public AddAdapter(Context context, List<AddBean> mans) {
this.context = context;
this.mans = mans;
layinf = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mans.size();
}
@Override
public int getItemViewType(int position) {
//这里是根据position返回指定的布局类型,比如男的返回0,女的返回1,会根据这个返回值加载不同布局
return mans.get(position).id;
}
@Override
public int getViewTypeCount() {
//这里是adapter里有几种布局
return 2;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final AddBean bean = mans.get(position);
//第一个布局的holder
ViewManHolder vhMan = null;
//第二个布局的holder
ViewWoManHolder vhWoMan = null;
if(convertView == null){
switch (bean.id){
case 0:
convertView = layinf.inflate(R.layout.item_man ,null);
vhMan = new ViewManHolder(convertView);
convertView.setTag(vhMan);
break;
case 1:
convertV