0
我有一个使用CustomAdapter
的列表视图。首先,我尝试使用ArrayAdapter显示我的listvew,并且所有项目看起来都不错。但是当我尝试用自定义适配器更改它们时,所有项目都消失了。这里是我的ArrayList我的列表视图为空
public ArrayList<HashMap<String,String>> getAllAssignment() {
ArrayList<HashMap<String,String>> daftarAssignment = new ArrayList<HashMap<String,String>>();
Cursor cursor = database.rawQuery("select customer.name from assignment, customer where"+
" assignment.customerid=customer.customerid and employeeid = '"+Globals.salesid+"'", null);
cursor.moveToFirst();
if (cursor.moveToFirst()) {
do {
map1 = new HashMap<String,String>();
name=cursor.getString(cursor.getColumnIndex(DBHelper.NAME));
map1.put("one",String.valueOf(daftarAssignment.size()));
map1.put("two",name);
daftarAssignment.add(map1);
} while (cursor.moveToNext());
}
cursor.close();
return daftarAssignment;
}
这里是我的适配器
ListAssignment= dataSource.getAllAssignment();
adapter = new CustomAdapter(ListAssignment.this, ListAssignment, R.layout.item_list,
new String[] {"two"},
new int[] {R.id.edtype});
和我CustomAdapter()
package ims.app.mobileorder;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
public class CustomAdapter extends SimpleAdapter{
private int[] colors = new int[] { Color.parseColor("#3BB9FF"), Color.parseColor("#306EFF") };
public CustomAdapter(Context context, ArrayList<HashMap<String,String>> mylist, int itemTo,
String[] from, int[] to) {
super(context, mylist, itemTo, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
return view;
}
}
显示适配器代码 –
第一次尝试使用呼叫日志类getAllAssignment()方法后打印列表的大小。 –
Check getCount mush返回data.size()/ data.length –