Last active
July 23, 2017 13:30
-
-
Save mikkipastel/3d76db92608d5d6acb5f41430b151b53 to your computer and use it in GitHub Desktop.
Show list by Listview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#000000"> | |
<ListView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:id="@+id/songlist" /> | |
</FrameLayout> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mikkipastel.exoplanet.playlist; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import com.mikkipastel.exoplanet.R; | |
public class ListAdapter extends BaseAdapter { | |
Context mContext; | |
int[] mCover; | |
String[] mSongName; | |
public listAdapter(Context context, int[] cover, String[] songname){ | |
this.mContext = context; | |
this.mCover = cover; | |
this.mSongName = songname; | |
} | |
@Override | |
public int getCount() { | |
return mSongName.length; | |
} | |
@Override | |
public Object getItem(int i) { | |
return null; | |
} | |
@Override | |
public long getItemId(int i) { | |
return 0; | |
} | |
@Override | |
public View getView(int i, View view, ViewGroup viewGroup) { | |
LayoutInflater mInflater = | |
(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
if (view == null) | |
view = mInflater.inflate(R.layout.item_track, viewGroup, false); | |
// set cover and track name | |
ImageView cover = (ImageView)view.findViewById(R.id.imageTrack); | |
cover.setImageResource(mCover[i]); | |
TextView name = (TextView)view.findViewById(R.id.nameTrack); | |
name.setText(mSongName[i]); | |
return view; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mikkipastel.exoplanet.playlist; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.Fragment; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.AdapterView; | |
import com.mikkipastel.exoplanet.R; | |
import com.mikkipastel.exoplanet.player.PlayerFragment; | |
public class PlaylistFragment extends Fragment { | |
ListView songListView; | |
ListAdapter adapter; | |
// sample to show before get from firebase storage | |
int[] cover = {R.drawable.cover01, | |
R.drawable.cover02, | |
R.drawable.cover03, | |
R.drawable.cover04, | |
R.drawable.cover05}; | |
String[] songname = {"Breaks 6-29-2560 BE, 12_31 PM.wav", | |
"Essential EDM 6-23-2560 BE, 5_24 PM.wav", | |
"Hip Hop 6-27-2560 BE, 7_12 PM.wav", | |
"House 2 6-28-2560 BE, 9_08 PM.wav", | |
"House 6-23-2560 BE, 5_43 PM.wav"}; | |
public PlaylistFragment() { | |
super(); | |
} | |
public static PlaylistFragment newInstance() { | |
PlaylistFragment fragment = new PlaylistFragment(); | |
Bundle args = new Bundle(); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View rootView = inflater.inflate(R.layout.fragment_playlist, container, false); | |
initInstances(rootView); | |
return rootView; | |
} | |
public void initInstances(View rootView){ | |
songListView = (ListView)rootView.findViewById(R.id.songlist); | |
adapter = new ListAdapter(getContext(), cover, songname); | |
songListView.setAdapter(adapter); | |
songListView.setOnItemClickListener(listViewItemClickListener); | |
} | |
final AdapterView.OnItemClickListener listViewItemClickListener = new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
if (position < cover.length){ | |
PlayerFragment.FragmentListener listener = (PlayerFragment.FragmentListener) getActivity(); | |
listener.onListItemClick(position); | |
} | |
} | |
}; | |
@Override | |
public void onStart() { | |
super.onStart(); | |
} | |
@Override | |
public void onStop() { | |
super.onStop(); | |
} | |
/* | |
* Save Instance State Here | |
*/ | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
// Save Instance State here | |
} | |
/* | |
* Restore Instance State Here | |
*/ | |
@Override | |
public void onActivityCreated(Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
if (savedInstanceState != null) { | |
// Restore Instance State here | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment