问题
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