0

Below is my code for base adapter. I will be using this class as an adapter for a ListView.

public class CustombaseAdapterTxnCartSelect extends BaseAdapter
{
    private Context mContext;
    private List<RowItemTxnCartSelect> mRowItems;

    TextView standDesc, seats, totalTicketTariff, eventDesc;

    public CustombaseAdapterTxnCartSelect(Context context, List<RowItemTxnCartSelect> rowItems) {
        mContext = context;
        mRowItems = rowItems;       
    }

    @Override
    public int getCount() {
        return mRowItems.size();
    }

    @Override
    public Object getItem(int position) {
        return mRowItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mRowItems.indexOf(getItem(position));
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = null;

        LayoutInflater mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflator.inflate(R.layout.event_layout_txn__cart_select, null);
        standDesc = (TextView) convertView.findViewById(R.id.textViewTxnCartSelectStandDesc);
        seats = (TextView) convertView.findViewById(R.id.textViewTxnCartSelectSeats);
        totalTicketTariff = (TextView) convertView.findViewById(R.id.textViewTxnCartSelectTotalTicketTariff);
        eventDesc = (TextView) convertView.findViewById(R.id.textViewEventDesc);

        RowItemTxnCartSelect row = (RowItemTxnCartSelect) getItem(position);
        standDesc.setText(row.getmStandDesc());
        seats.setText(row.getmSeats());
        totalTicketTariff.setText(row.getMtotalTicketTariff());
        eventDesc.setText(row.getmEventDesc());

        return convertView;
    }
}

I just want to convert it into an expandable list view I'm not clear about what all I have to add.

Sandy Chapman
  • 11,133
  • 3
  • 58
  • 67
Rahul
  • 9
  • 6

2 Answers2

0

maybe you could something like this :

public class FevList extends ExpandableListActivity {
    String title;
    String url;
    SQLiteDatabase database;
    DbUtil db;
    HashMap<String, String> map = new HashMap<String, String>();
    ArrayList<HashMap<String, String>> subjectList = new ArrayList<HashMap<String, String>>();


    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.exlist);
            db = new DbUtil();
            database = db.openConnection(this);
            // Thread for getting values of title from DataBase.
            SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
                    this, createGroupList(), R.layout.group_row,
                    new String[] { "subject" }, new int[] { R.id.row_name },
                    createChildList(), R.layout.child_row,
                    new String[] { "title" }, new int[] { R.id.grp_child });
            setListAdapter(expListAdapter);
            registerForContextMenu(getExpandableListView());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

// code for adapter

/* Creating the Hashmap for the row */ ArrayList> result = new ArrayList>();

            @SuppressWarnings("unchecked")
            private List createGroupList() {

// write your code here.

                return (List) result;

            }

            /* creatin the HashMap for the children */

            @SuppressWarnings("unchecked")
            private List createChildList() {

// write your code here.
                return result;
            }

            public void onContentChanged() {

                System.out.println("onContentChanged");

                super.onContentChanged();

            }

            /* This function is called on each child click */

            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {

// write your code here.

                return true;

            }

            /* This function is called on expansion of the group */

            public void onGroupExpand(int groupPosition) {

                try {

                    System.out.println("Group exapanding Listener => groupPosition = "
                            + groupPosition);

                } catch (Exception e) {

                    System.out.println(" groupPosition Errrr +++ " + e.getMessage());

                }

            }
        }

this is a snippet , you could refer to this

Community
  • 1
  • 1
ziad.mediaphone
  • 21
  • 1
  • 10
0

Here is an Opensource example project to demonstrate ExpandableListView. It is good example to getting started with Expandable Listviews.

Waqar Khan
  • 468
  • 4
  • 18