下面这一行是界面显示的时候生成的
String[]data1 = new String[]{"类别","点名","X","Y","A","S","L"}; dList = new ArrayList<HashMap<String,String>>(); data.put("LB",data1[0]); data.put("DM",data1[1]); data.put("X",data1[2]); data.put("Y",data1[3]); data.put("A",data1[4]); data.put("S",data1[5]); data.put("L",data1[6]); dList.add(data); sAd = new SimpleAdapter(this,dList,R.layout.list, new String[]{"LB","DM","X","Y","A","S"}, new int[]{R.id.list_LB,R.id.list_DM,R.id.list_X,R.id.list_Y,R.id.list_A,R.id.list_S}); List1.setAdapter(sAd);
下面的代码是通过触发“增加”按钮来增加一行数据
String[]data2 = new String[]{QSname.getText().toString(),QSX.getText().toString(),QSY.getText().toString(),"A","S","L"}; dList = new ArrayList<HashMap<String,String>>(); data.put("DM",data2[0]); data.put("X",data2[1]); data.put("Y",data2[2]); data.put("A",data2[3]); data.put("S",data2[4]); data.put("L",data2[5]); sAd = new SimpleAdapter(this,dList,R.layout.list, new String[]{"DM","X","Y","A","S","L"}, new int[]{R.id.list_DM,R.id.list_X,R.id.list_Y,R.id.list_A,R.id.list_S,R.id.list_L}); List1.setAdapter(sAd); sAd.notifyDataSetChanged();
想每次通过增加按钮来增加一行数据,但是每一次增加后,ListView只显示新的数据,并覆盖掉上一行,只有一行数据
急求高手给解决!刚开始学android,望赐教!
解决方案
20
public SimpleAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
mData = data;
mResource = mDropDownResource = resource;
mFrom = from;
mTo = to;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
这是源码, List<? extends Map<String, ?>> data,在你这里是dList, dList.add(data)没有;
int resource, String[] from, int[] to) {
mData = data;
mResource = mDropDownResource = resource;
mFrom = from;
mTo = to;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
这是源码, List<? extends Map<String, ?>> data,在你这里是dList, dList.add(data)没有;
20
1.你的第二段代码为啥要重新new dlist呢,
2.第二段代码为啥没有dlist。add(data)呢
2.第二段代码为啥没有dlist。add(data)呢