Prevent ListView Item refresh when adding another Item dynamically using Android

六眼飞鱼酱① 提交于 2020-01-16 00:46:11

问题


I am using BaseAdapter to bind Custom ListView. And I am adding Items dynamically. Each Item contains TextView, EditText, Spinner. It is working fine. But now issue is that if user selects any value from Spinner, add some data in EditText and then if he/she adds new item then it clears all values of filled up data.

So, I want to prevent this refresh of already added Items when add new Item. How to do this ?

My Code :

ArrayList<HashMap<String, String>> aaName = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = null;

map = new HashMap<String, String>();
map.put("Name", Name value);
aaName.add(map);
NameAdapter nameAdapter = new NameAdapter(getActivity(), aaName);
lvName.setAdapter(nameAdapter);

public class NameAdapter extends BaseAdapter {

    public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.chiefcomment_view, null);

    TextView tvName = (TextView) vi.findViewById(R.id.tvName);
    Spinner spnTime = (Spinner) vi.findViewById(R.id.spnTime);
    EditText etSpecification = (EditText) vi.findViewById(R.id.etSpecification);

    HashMap<String, String> name = new HashMap<String, String>();
    name = data.get(position);

    tvName.setText(name.get("Name"));

    // Time Spinner...
    ArrayList<String> Time = new ArrayList<String>();
    for (int i = 1; i <= 100; i++) {
        Time.add(String.valueOf(i));
    }
    aaTime = new ArrayAdapter<String>(activity, R.layout.small_spinner_view, Time);
    spnTime.setAdapter(aaTime);

    return vi;
    }
}

来源:https://stackoverflow.com/questions/26155365/prevent-listview-item-refresh-when-adding-another-item-dynamically-using-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!