dimanche 3 mai 2015

Custom ListView with Category as SectionHeader (Used custom CursorAdapter)

I want to display ListView with Category as SectionHeader.

I am displaying ListView from sqlite database using custom CursorAdapter:

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);


    }
}

And i am calling in these way the 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);

Now i am trying to achieve this: All items in the listview have certain category, and i want them to separate with Category as section header, what i need to change to my Adapter to have this ?!?

Aucun commentaire:

Enregistrer un commentaire