从SQLLite获取数据集并在Spinner中填充

时间:2015-09-25 13:44:48

标签: android sql sqlite

我想从db中读出客户并在Spinner中填充它们。下面的代码没有错误,但我希望具有相同First和Lastname的客户应该只在旋转器中显示一次,而不是两次。这不起作用,我怎么能这样做?

DBHelper

public String[] getCustomerList() {

            String query = "Select * FROM " + CUSTOMER;
            SQLiteDatabase db = this.getWritableDatabase();

            ArrayList<String> cusList = new ArrayList<String>();

            Cursor cursor = db.rawQuery(query, null);
            if (cursor.moveToFirst()) {
                do {
                    cusList.add(cursor.getString(cursor.getColumnIndex(COLUMN_FIRSTNAME)) + " "
                            + cursor.getString(cursor.getColumnIndex(COLUMN_SECONDNAME)));
                }
                while (cursor.moveToNext());
            }
            String[] result = cusList.toArray(new String[cusList.size()]);
            Arrays.sort(result);

            return result;
        }

方法getCustomerList()

private String[] getCustomerList() {
    String[] customerList;        
    customerList= dbHelper.getcustomerList();

填充ArrayAdapter ..

 adapterCar = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, getCustomerList());

0 个答案:

没有答案