How to navigate from an activity having a Recyclerview and Cardview to another activity [closed]










0















I want to make an app with gridmenu in android studio. I have made a design, but i can`t make an intent activity with it. How can i make intent activity from Recyclerview and cardview from this code :



PlaylistAdapter.java :



public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder>

private static final String TAG = PlaylistAdapter.class.getSimpleName();

private Context context;
private List<PlaylistObject> playlists;

public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
this.context = context;
this.playlists = playlists;


@Override
public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
return new PlaylistViewHolder(view);


@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position)
PlaylistObject playlistObject = playlists.get(position);
holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());



@Override
public int getItemCount()
return playlists.size();




PlaylistFragment.java :



public class PlaylistFragment extends Fragment 

public PlaylistFragment()


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_playlist, container, false);

RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
playlisRecyclerView.setLayoutManager(gridLayout);
playlisRecyclerView.setHasFixedSize(true);

PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());
playlisRecyclerView.setAdapter(mAdapter);

return view;


public List<PlaylistObject> getTestData()
List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));




fragment_playlist.xml :



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.inducesmile.androidmusicplayer
.fragment.PlaylistFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/your_play_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/_10sdp"
android:scrollbars="none" />

</LinearLayout>


playlist_layout



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/item_list"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginBottom="@dimen/_8sdp"
android:paddingLeft="@dimen/_4sdp"
android:paddingRight="@dimen/_4sdp"

android:orientation="vertical">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/play_list_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:padding="20dp"
android:src="@drawable/prf1"
android:contentDescription="@string/app_name"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">

<TextView
android:id="@+id/play_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="@string/profile"
android:textColor="@color/colorWhite"/>

</LinearLayout>
</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>


anyone can help me??
thank you










share|improve this question















closed as unclear what you're asking by Mike M., Unheilig, Shiladitya, ADM, Billal Begueradj Nov 15 '18 at 5:50


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • where is this cardview.? show your layout please

    – Jins Lukose
    Nov 15 '18 at 5:41












  • my apologize, that`s my layout

    – Tri Ako Nugroho
    Nov 15 '18 at 8:51











  • so you want to navigate to another activity while clicking any items in recyclerview, right?

    – Jins Lukose
    Nov 15 '18 at 11:37











  • yes it is sir, i want navigate to another or new activity

    – Tri Ako Nugroho
    Nov 15 '18 at 12:37











  • i think this question is closed since your question was unclear. please ask this again. i will answer. the answer is simple use same intent but just pass context to start an activity .check this codingwithmitch.com/android/65 if you want get more details please ask the question once again

    – Jins Lukose
    Nov 16 '18 at 4:36
















0















I want to make an app with gridmenu in android studio. I have made a design, but i can`t make an intent activity with it. How can i make intent activity from Recyclerview and cardview from this code :



PlaylistAdapter.java :



public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder>

private static final String TAG = PlaylistAdapter.class.getSimpleName();

private Context context;
private List<PlaylistObject> playlists;

public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
this.context = context;
this.playlists = playlists;


@Override
public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
return new PlaylistViewHolder(view);


@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position)
PlaylistObject playlistObject = playlists.get(position);
holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());



@Override
public int getItemCount()
return playlists.size();




PlaylistFragment.java :



public class PlaylistFragment extends Fragment 

public PlaylistFragment()


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_playlist, container, false);

RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
playlisRecyclerView.setLayoutManager(gridLayout);
playlisRecyclerView.setHasFixedSize(true);

PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());
playlisRecyclerView.setAdapter(mAdapter);

return view;


public List<PlaylistObject> getTestData()
List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));




fragment_playlist.xml :



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.inducesmile.androidmusicplayer
.fragment.PlaylistFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/your_play_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/_10sdp"
android:scrollbars="none" />

</LinearLayout>


playlist_layout



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/item_list"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginBottom="@dimen/_8sdp"
android:paddingLeft="@dimen/_4sdp"
android:paddingRight="@dimen/_4sdp"

android:orientation="vertical">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/play_list_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:padding="20dp"
android:src="@drawable/prf1"
android:contentDescription="@string/app_name"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">

<TextView
android:id="@+id/play_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="@string/profile"
android:textColor="@color/colorWhite"/>

</LinearLayout>
</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>


anyone can help me??
thank you










share|improve this question















closed as unclear what you're asking by Mike M., Unheilig, Shiladitya, ADM, Billal Begueradj Nov 15 '18 at 5:50


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • where is this cardview.? show your layout please

    – Jins Lukose
    Nov 15 '18 at 5:41












  • my apologize, that`s my layout

    – Tri Ako Nugroho
    Nov 15 '18 at 8:51











  • so you want to navigate to another activity while clicking any items in recyclerview, right?

    – Jins Lukose
    Nov 15 '18 at 11:37











  • yes it is sir, i want navigate to another or new activity

    – Tri Ako Nugroho
    Nov 15 '18 at 12:37











  • i think this question is closed since your question was unclear. please ask this again. i will answer. the answer is simple use same intent but just pass context to start an activity .check this codingwithmitch.com/android/65 if you want get more details please ask the question once again

    – Jins Lukose
    Nov 16 '18 at 4:36














0












0








0








I want to make an app with gridmenu in android studio. I have made a design, but i can`t make an intent activity with it. How can i make intent activity from Recyclerview and cardview from this code :



PlaylistAdapter.java :



public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder>

private static final String TAG = PlaylistAdapter.class.getSimpleName();

private Context context;
private List<PlaylistObject> playlists;

public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
this.context = context;
this.playlists = playlists;


@Override
public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
return new PlaylistViewHolder(view);


@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position)
PlaylistObject playlistObject = playlists.get(position);
holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());



@Override
public int getItemCount()
return playlists.size();




PlaylistFragment.java :



public class PlaylistFragment extends Fragment 

public PlaylistFragment()


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_playlist, container, false);

RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
playlisRecyclerView.setLayoutManager(gridLayout);
playlisRecyclerView.setHasFixedSize(true);

PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());
playlisRecyclerView.setAdapter(mAdapter);

return view;


public List<PlaylistObject> getTestData()
List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));




fragment_playlist.xml :



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.inducesmile.androidmusicplayer
.fragment.PlaylistFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/your_play_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/_10sdp"
android:scrollbars="none" />

</LinearLayout>


playlist_layout



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/item_list"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginBottom="@dimen/_8sdp"
android:paddingLeft="@dimen/_4sdp"
android:paddingRight="@dimen/_4sdp"

android:orientation="vertical">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/play_list_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:padding="20dp"
android:src="@drawable/prf1"
android:contentDescription="@string/app_name"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">

<TextView
android:id="@+id/play_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="@string/profile"
android:textColor="@color/colorWhite"/>

</LinearLayout>
</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>


anyone can help me??
thank you










share|improve this question
















I want to make an app with gridmenu in android studio. I have made a design, but i can`t make an intent activity with it. How can i make intent activity from Recyclerview and cardview from this code :



PlaylistAdapter.java :



public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder>

private static final String TAG = PlaylistAdapter.class.getSimpleName();

private Context context;
private List<PlaylistObject> playlists;

public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
this.context = context;
this.playlists = playlists;


@Override
public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
return new PlaylistViewHolder(view);


@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position)
PlaylistObject playlistObject = playlists.get(position);
holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());



@Override
public int getItemCount()
return playlists.size();




PlaylistFragment.java :



public class PlaylistFragment extends Fragment 

public PlaylistFragment()


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_playlist, container, false);

RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
playlisRecyclerView.setLayoutManager(gridLayout);
playlisRecyclerView.setHasFixedSize(true);

PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());
playlisRecyclerView.setAdapter(mAdapter);

return view;


public List<PlaylistObject> getTestData()
List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));




fragment_playlist.xml :



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.inducesmile.androidmusicplayer
.fragment.PlaylistFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/your_play_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/_10sdp"
android:scrollbars="none" />

</LinearLayout>


playlist_layout



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/item_list"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginBottom="@dimen/_8sdp"
android:paddingLeft="@dimen/_4sdp"
android:paddingRight="@dimen/_4sdp"

android:orientation="vertical">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/play_list_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:padding="20dp"
android:src="@drawable/prf1"
android:contentDescription="@string/app_name"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">

<TextView
android:id="@+id/play_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="@string/profile"
android:textColor="@color/colorWhite"/>

</LinearLayout>
</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>


anyone can help me??
thank you







android android-studio android-layout android-intent






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 15:35









Jins Lukose

638315




638315










asked Nov 15 '18 at 2:34









Tri Ako NugrohoTri Ako Nugroho

134




134




closed as unclear what you're asking by Mike M., Unheilig, Shiladitya, ADM, Billal Begueradj Nov 15 '18 at 5:50


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Mike M., Unheilig, Shiladitya, ADM, Billal Begueradj Nov 15 '18 at 5:50


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • where is this cardview.? show your layout please

    – Jins Lukose
    Nov 15 '18 at 5:41












  • my apologize, that`s my layout

    – Tri Ako Nugroho
    Nov 15 '18 at 8:51











  • so you want to navigate to another activity while clicking any items in recyclerview, right?

    – Jins Lukose
    Nov 15 '18 at 11:37











  • yes it is sir, i want navigate to another or new activity

    – Tri Ako Nugroho
    Nov 15 '18 at 12:37











  • i think this question is closed since your question was unclear. please ask this again. i will answer. the answer is simple use same intent but just pass context to start an activity .check this codingwithmitch.com/android/65 if you want get more details please ask the question once again

    – Jins Lukose
    Nov 16 '18 at 4:36


















  • where is this cardview.? show your layout please

    – Jins Lukose
    Nov 15 '18 at 5:41












  • my apologize, that`s my layout

    – Tri Ako Nugroho
    Nov 15 '18 at 8:51











  • so you want to navigate to another activity while clicking any items in recyclerview, right?

    – Jins Lukose
    Nov 15 '18 at 11:37











  • yes it is sir, i want navigate to another or new activity

    – Tri Ako Nugroho
    Nov 15 '18 at 12:37











  • i think this question is closed since your question was unclear. please ask this again. i will answer. the answer is simple use same intent but just pass context to start an activity .check this codingwithmitch.com/android/65 if you want get more details please ask the question once again

    – Jins Lukose
    Nov 16 '18 at 4:36

















where is this cardview.? show your layout please

– Jins Lukose
Nov 15 '18 at 5:41






where is this cardview.? show your layout please

– Jins Lukose
Nov 15 '18 at 5:41














my apologize, that`s my layout

– Tri Ako Nugroho
Nov 15 '18 at 8:51





my apologize, that`s my layout

– Tri Ako Nugroho
Nov 15 '18 at 8:51













so you want to navigate to another activity while clicking any items in recyclerview, right?

– Jins Lukose
Nov 15 '18 at 11:37





so you want to navigate to another activity while clicking any items in recyclerview, right?

– Jins Lukose
Nov 15 '18 at 11:37













yes it is sir, i want navigate to another or new activity

– Tri Ako Nugroho
Nov 15 '18 at 12:37





yes it is sir, i want navigate to another or new activity

– Tri Ako Nugroho
Nov 15 '18 at 12:37













i think this question is closed since your question was unclear. please ask this again. i will answer. the answer is simple use same intent but just pass context to start an activity .check this codingwithmitch.com/android/65 if you want get more details please ask the question once again

– Jins Lukose
Nov 16 '18 at 4:36






i think this question is closed since your question was unclear. please ask this again. i will answer. the answer is simple use same intent but just pass context to start an activity .check this codingwithmitch.com/android/65 if you want get more details please ask the question once again

– Jins Lukose
Nov 16 '18 at 4:36













1 Answer
1






active

oldest

votes


















1














public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder> 

private static final String TAG = PlaylistAdapter.class.getSimpleName();

private Context context;
private List<PlaylistObject> playlists;

private OnItemClickListener mOnItemClickListener;

public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
this.context = context;
this.playlists = playlists;


// Set the click listener
public void setOnItemClickListener(OnItemClickListener onItemClickListener)
mOnItemClickListener = onItemClickListener;


@Override
public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
return new PlaylistViewHolder(view);


@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position)
PlaylistObject playlistObject = playlists.get(position);
holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());

// Whole item
holder.itemView.setOnClickListener(new View.OnClickListener
@Override
public void onClick(View v)
if(mOnItemClickListener != null)
mOnItemClickListener.onItemClick();


);

// Or Title
holder.playlistTitle.setOnClickListener(new View.OnClickListener
@Override
public void onClick(View v)
if(mOnItemClickListener != null)
mOnItemClickListener.onItemClick();


);

// Or Cover
holder.playlistCover.setOnClickListener(new View.OnClickListener
@Override
public void onClick(View v)
if(mOnItemClickListener != null)
mOnItemClickListener.onItemClick();


);


@Override
public int getItemCount()
return playlists.size();


// The Item click listener
public interface OnItemClickListener

void onItemClick();




Adapter add a OnItemClickListener, and Fragment implements this Listener



public class PlaylistFragment extends Fragment implements PlaylistAdapter.OnItemClickListener 

public PlaylistFragment()



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_playlist, container, false);

RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
playlisRecyclerView.setLayoutManager(gridLayout);
playlisRecyclerView.setHasFixedSize(true);

PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());

// Set the click listener
mAdapter.setOnItemClickListener(this);

playlisRecyclerView.setAdapter(mAdapter);

return view;


public List<PlaylistObject> getTestData()
List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));


@Override
public void onItemClick()
// Do what you want do
//startActivity(new Intent(getActivity(), XXXXActivity.class));







share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder> 

    private static final String TAG = PlaylistAdapter.class.getSimpleName();

    private Context context;
    private List<PlaylistObject> playlists;

    private OnItemClickListener mOnItemClickListener;

    public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
    this.context = context;
    this.playlists = playlists;


    // Set the click listener
    public void setOnItemClickListener(OnItemClickListener onItemClickListener)
    mOnItemClickListener = onItemClickListener;


    @Override
    public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
    return new PlaylistViewHolder(view);


    @Override
    public void onBindViewHolder(PlaylistViewHolder holder, int position)
    PlaylistObject playlistObject = playlists.get(position);
    holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
    holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());

    // Whole item
    holder.itemView.setOnClickListener(new View.OnClickListener
    @Override
    public void onClick(View v)
    if(mOnItemClickListener != null)
    mOnItemClickListener.onItemClick();


    );

    // Or Title
    holder.playlistTitle.setOnClickListener(new View.OnClickListener
    @Override
    public void onClick(View v)
    if(mOnItemClickListener != null)
    mOnItemClickListener.onItemClick();


    );

    // Or Cover
    holder.playlistCover.setOnClickListener(new View.OnClickListener
    @Override
    public void onClick(View v)
    if(mOnItemClickListener != null)
    mOnItemClickListener.onItemClick();


    );


    @Override
    public int getItemCount()
    return playlists.size();


    // The Item click listener
    public interface OnItemClickListener

    void onItemClick();




    Adapter add a OnItemClickListener, and Fragment implements this Listener



    public class PlaylistFragment extends Fragment implements PlaylistAdapter.OnItemClickListener 

    public PlaylistFragment()



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    View view = inflater.inflate(R.layout.fragment_playlist, container, false);

    RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
    GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
    playlisRecyclerView.setLayoutManager(gridLayout);
    playlisRecyclerView.setHasFixedSize(true);

    PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());

    // Set the click listener
    mAdapter.setOnItemClickListener(this);

    playlisRecyclerView.setAdapter(mAdapter);

    return view;


    public List<PlaylistObject> getTestData()
    List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
    trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
    trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
    trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
    trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));


    @Override
    public void onItemClick()
    // Do what you want do
    //startActivity(new Intent(getActivity(), XXXXActivity.class));







    share|improve this answer



























      1














      public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder> 

      private static final String TAG = PlaylistAdapter.class.getSimpleName();

      private Context context;
      private List<PlaylistObject> playlists;

      private OnItemClickListener mOnItemClickListener;

      public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
      this.context = context;
      this.playlists = playlists;


      // Set the click listener
      public void setOnItemClickListener(OnItemClickListener onItemClickListener)
      mOnItemClickListener = onItemClickListener;


      @Override
      public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
      View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
      return new PlaylistViewHolder(view);


      @Override
      public void onBindViewHolder(PlaylistViewHolder holder, int position)
      PlaylistObject playlistObject = playlists.get(position);
      holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
      holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());

      // Whole item
      holder.itemView.setOnClickListener(new View.OnClickListener
      @Override
      public void onClick(View v)
      if(mOnItemClickListener != null)
      mOnItemClickListener.onItemClick();


      );

      // Or Title
      holder.playlistTitle.setOnClickListener(new View.OnClickListener
      @Override
      public void onClick(View v)
      if(mOnItemClickListener != null)
      mOnItemClickListener.onItemClick();


      );

      // Or Cover
      holder.playlistCover.setOnClickListener(new View.OnClickListener
      @Override
      public void onClick(View v)
      if(mOnItemClickListener != null)
      mOnItemClickListener.onItemClick();


      );


      @Override
      public int getItemCount()
      return playlists.size();


      // The Item click listener
      public interface OnItemClickListener

      void onItemClick();




      Adapter add a OnItemClickListener, and Fragment implements this Listener



      public class PlaylistFragment extends Fragment implements PlaylistAdapter.OnItemClickListener 

      public PlaylistFragment()



      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
      View view = inflater.inflate(R.layout.fragment_playlist, container, false);

      RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
      GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
      playlisRecyclerView.setLayoutManager(gridLayout);
      playlisRecyclerView.setHasFixedSize(true);

      PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());

      // Set the click listener
      mAdapter.setOnItemClickListener(this);

      playlisRecyclerView.setAdapter(mAdapter);

      return view;


      public List<PlaylistObject> getTestData()
      List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
      trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
      trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
      trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
      trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));


      @Override
      public void onItemClick()
      // Do what you want do
      //startActivity(new Intent(getActivity(), XXXXActivity.class));







      share|improve this answer

























        1












        1








        1







        public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder> 

        private static final String TAG = PlaylistAdapter.class.getSimpleName();

        private Context context;
        private List<PlaylistObject> playlists;

        private OnItemClickListener mOnItemClickListener;

        public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
        this.context = context;
        this.playlists = playlists;


        // Set the click listener
        public void setOnItemClickListener(OnItemClickListener onItemClickListener)
        mOnItemClickListener = onItemClickListener;


        @Override
        public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
        return new PlaylistViewHolder(view);


        @Override
        public void onBindViewHolder(PlaylistViewHolder holder, int position)
        PlaylistObject playlistObject = playlists.get(position);
        holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
        holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());

        // Whole item
        holder.itemView.setOnClickListener(new View.OnClickListener
        @Override
        public void onClick(View v)
        if(mOnItemClickListener != null)
        mOnItemClickListener.onItemClick();


        );

        // Or Title
        holder.playlistTitle.setOnClickListener(new View.OnClickListener
        @Override
        public void onClick(View v)
        if(mOnItemClickListener != null)
        mOnItemClickListener.onItemClick();


        );

        // Or Cover
        holder.playlistCover.setOnClickListener(new View.OnClickListener
        @Override
        public void onClick(View v)
        if(mOnItemClickListener != null)
        mOnItemClickListener.onItemClick();


        );


        @Override
        public int getItemCount()
        return playlists.size();


        // The Item click listener
        public interface OnItemClickListener

        void onItemClick();




        Adapter add a OnItemClickListener, and Fragment implements this Listener



        public class PlaylistFragment extends Fragment implements PlaylistAdapter.OnItemClickListener 

        public PlaylistFragment()



        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        View view = inflater.inflate(R.layout.fragment_playlist, container, false);

        RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
        GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
        playlisRecyclerView.setLayoutManager(gridLayout);
        playlisRecyclerView.setHasFixedSize(true);

        PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());

        // Set the click listener
        mAdapter.setOnItemClickListener(this);

        playlisRecyclerView.setAdapter(mAdapter);

        return view;


        public List<PlaylistObject> getTestData()
        List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
        trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
        trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
        trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
        trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));


        @Override
        public void onItemClick()
        // Do what you want do
        //startActivity(new Intent(getActivity(), XXXXActivity.class));







        share|improve this answer













        public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistViewHolder> 

        private static final String TAG = PlaylistAdapter.class.getSimpleName();

        private Context context;
        private List<PlaylistObject> playlists;

        private OnItemClickListener mOnItemClickListener;

        public PlaylistAdapter(Context context, List<PlaylistObject> playlists)
        this.context = context;
        this.playlists = playlists;


        // Set the click listener
        public void setOnItemClickListener(OnItemClickListener onItemClickListener)
        mOnItemClickListener = onItemClickListener;


        @Override
        public PlaylistViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        View view = LayoutInflater.from(context).inflate(R.layout.play_list_layout, parent, false);
        return new PlaylistViewHolder(view);


        @Override
        public void onBindViewHolder(PlaylistViewHolder holder, int position)
        PlaylistObject playlistObject = playlists.get(position);
        holder.playlistTitle.setText(playlistObject.getPlaylistTitle());
        holder.playlistCover.setImageResource(playlistObject.getPlaylistCover());

        // Whole item
        holder.itemView.setOnClickListener(new View.OnClickListener
        @Override
        public void onClick(View v)
        if(mOnItemClickListener != null)
        mOnItemClickListener.onItemClick();


        );

        // Or Title
        holder.playlistTitle.setOnClickListener(new View.OnClickListener
        @Override
        public void onClick(View v)
        if(mOnItemClickListener != null)
        mOnItemClickListener.onItemClick();


        );

        // Or Cover
        holder.playlistCover.setOnClickListener(new View.OnClickListener
        @Override
        public void onClick(View v)
        if(mOnItemClickListener != null)
        mOnItemClickListener.onItemClick();


        );


        @Override
        public int getItemCount()
        return playlists.size();


        // The Item click listener
        public interface OnItemClickListener

        void onItemClick();




        Adapter add a OnItemClickListener, and Fragment implements this Listener



        public class PlaylistFragment extends Fragment implements PlaylistAdapter.OnItemClickListener 

        public PlaylistFragment()



        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        View view = inflater.inflate(R.layout.fragment_playlist, container, false);

        RecyclerView playlisRecyclerView = (RecyclerView)view.findViewById(R.id.your_play_list);
        GridLayoutManager gridLayout = new GridLayoutManager(getActivity(), 2);
        playlisRecyclerView.setLayoutManager(gridLayout);
        playlisRecyclerView.setHasFixedSize(true);

        PlaylistAdapter mAdapter = new PlaylistAdapter(getActivity(), getTestData());

        // Set the click listener
        mAdapter.setOnItemClickListener(this);

        playlisRecyclerView.setAdapter(mAdapter);

        return view;


        public List<PlaylistObject> getTestData()
        List<PlaylistObject> trackList = new ArrayList<PlaylistObject>();
        trackList.add(new PlaylistObject("My Account", "12 tracks", R.drawable.prf1));
        trackList.add(new PlaylistObject("My Teacher", "12 tracks", R.drawable.teacher));
        trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));
        trackList.add(new PlaylistObject("Falling over", "12 tracks", R.drawable.album2));


        @Override
        public void onItemClick()
        // Do what you want do
        //startActivity(new Intent(getActivity(), XXXXActivity.class));








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 3:29









        ZhiYao WangZhiYao Wang

        357




        357















            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto