Java tutorial
/* * SoundBox - Android Music Player * Copyright (C) 2013 Ivn Arcuschin Moreno * * This file is part of SoundBox. * * SoundBox is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * SoundBox is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SoundBox. If not, see <http://www.gnu.org/licenses/>. */ package com.arcusapp.soundbox.fragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import com.arcusapp.soundbox.R; import com.arcusapp.soundbox.adapter.ArtistsActivityAdapter; public class ArtistsFragment extends Fragment { ArtistsActivityAdapter myAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myAdapter = new ArtistsActivityAdapter(this.getActivity()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_artists, container, false); ExpandableListView myExpandableList = (ExpandableListView) rootView .findViewById(R.id.expandableListArtists); myExpandableList.setGroupIndicator(null); myExpandableList.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { int groupPosition = ExpandableListView.getPackedPositionGroup(id); myAdapter.onArtistLongClick(groupPosition); return true; } else if (ExpandableListView .getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int groupPosition = ExpandableListView.getPackedPositionGroup(id); int childPosition = ExpandableListView.getPackedPositionChild(id); myAdapter.onAlbumLongClick(groupPosition, childPosition); return true; } return false; } }); myExpandableList.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { myAdapter.onAlbumClick(groupPosition, childPosition); return false; } }); myExpandableList.setAdapter(myAdapter); return rootView; } }