自定义ListView,类别为SectionHeader(使用自定义CursorAdapter)

时间:2015-05-03 08:58:15

标签: java android sqlite listview

我想将ListView与Category一起显示为SectionHeader。

我使用自定义CursorAdapter:

从sqlite数据库显示ListView
public class ListAdapter extends CursorAdapter {


    public ListAdapter(Context context, Cursor c) {
        super(context, c);

    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return LayoutInflater.from(context).inflate(R.layout.single_identity, parent, false);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {



        Typeface face1= Typeface.createFromAsset(context.getAssets(),
                "fonts/RobotoSlab-Regular.ttf");


        String textTitle = cursor.getString(cursor.getColumnIndexOrThrow("name"));
        int intColor = cursor.getInt(cursor.getColumnIndexOrThrow("color"));
        String dateText = cursor.getString(cursor.getColumnIndexOrThrow("username"));


        String test = textTitle;
        char first = test.charAt(0);

        TextDrawable drawable1 = TextDrawable.builder()
                    .buildRound(String.valueOf(first).toUpperCase(), intColor);
            ImageView image = (ImageView) view.findViewById(R.id.image_view);
            image.setImageDrawable(drawable1);

           // TextView tt = (TextView) v.findViewById(R.id.id);
        TextView tt1 = (TextView) view.findViewById(R.id.friend_name);
        TextView tt3 = (TextView) view.findViewById(R.id.friend_state);

        tt1.setText(textTitle);
        tt1.setTypeface(face1);

        tt3.setText(dateText);
        tt3.setTypeface(face1);


    }
}

我用这种方式打电话给List:

SQLiteDatabase dbs = db.getWritableDatabase();
identityCursor = dbs.rawQuery("SELECT  * FROM Identities", null);
listView = (ListView) android.findViewById(R.id.listView1);

ListAdapter customAdapter = new ListAdapter(getActivity(), identityCursor);
listView.setAdapter(customAdapter);

现在我正在尝试实现这一点:列表视图中的所有项目都有某些类别,我希望它们与Category分隔为部分标题,我需要更改为我的适配器才能拥有它?!

0 个答案:

没有答案