private ArrayList<GalleryGridObject> galleryList = new ArrayList<GalleryGridObject>();
public class UserProfile_PhotoFragment extends Fragment {
private ArrayList<GalleryGridObject> galleryList;
private GalleryAdapter mAdapter;
private RecyclerView recyclerView;
public UserProfile_PhotoFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_user_profile_photo, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
mAdapter = new GalleryAdapter(this, galleryList);
recyclerView.setAdapter(mAdapter);
GridLayoutManager mGridLayoutManager = new GridLayoutManager(getActivity(), 3);
recyclerView.setLayoutManager(mGridLayoutManager);
recyclerView.setHasFixedSize(true);
prepareGalleryData();
return view;
}
private void prepareGalleryData()
{
GalleryGridObject gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
mAdapter.notifyDataSetChanged();
}
}
public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.ViewHolder> {
private UserProfile_PhotoFragment mContext;
private ArrayList<GalleryGridObject> galleryGridObjectArrayList;
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public ViewHolder(View view) {
super(view);
image = (ImageView)itemView.findViewById(R.id.tile_picture);
}
}
public GalleryAdapter(UserProfile_PhotoFragment mContext, ArrayList<GalleryGridObject> galleryGridObjectArrayList) {
this.mContext = mContext;
this.galleryGridObjectArrayList=galleryGridObjectArrayList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_gallery, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
GalleryGridObject image = galleryGridObjectArrayList.get(position);
holder.image.setImageResource(image.getGalleryImage());
}
@Override
public int getItemCount() {
return galleryGridObjectArrayList.size();
}
}
<include layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/BottomNavMain"/>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.asus.testapp147.MainActivity"
tools:showIn="@layout/activity_main">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.constraint.ConstraintLayout>
Process: com.example.asus.testapp147, PID: 29538
java.lang.IllegalArgumentException: No view found for id 0x7f080058 (com.example.asus.testapp147:id/content_frame) for fragment ProfileFragment{900146 #0 id=0x7f080058}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1413)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
@Override
public void onClick(View v) {
Fragment someFragment = new ProfileFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.content_frame, someFragment ); // give your fragment container id in first parameter
transaction.addToBackStack(null); // if written, this transaction will be added to backstack
transaction.commit();
}
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
private HomeFragment mContext;
private ArrayList<CardViewObject> postArrayList;
public RecyclerViewAdapter (HomeFragment mContext, ArrayList<CardViewObject> postArrayList){
this.mContext=mContext;
this.postArrayList=postArrayList;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_ITEM) {
//Inflating recycle view item layout
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card, parent, false);
return new ItemViewHolder(itemView);
} else if (viewType == TYPE_HEADER) {
//Inflating header view
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.information_of_day, parent, false);
return new HeaderViewHolder(itemView);
} else return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof HeaderViewHolder) {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.headerCity.setText("");
headerHolder.headerCountry.setText("");
headerHolder.headerTime.setText("");
headerHolder.headerTemperature.setText("");
} else if (holder instanceof ItemViewHolder) {
CardViewObject profiles = postArrayList.get(position);
((ItemViewHolder) holder).avatar.setImageResource(profiles.getCardAvatar());
((ItemViewHolder) holder).name.setText(profiles.getCardName());
((ItemViewHolder) holder).location.setText(profiles.getCardLocation());
((ItemViewHolder) holder).cardImage.setImageResource(profiles.getCardImage());
((ItemViewHolder) holder).description.setText(profiles.getCardDescription());
}
}
@Override
public int getItemCount() {
return postArrayList.size() + 1;
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position))
return TYPE_HEADER;
return TYPE_ITEM;
}
private boolean isPositionHeader(int position) {
return position == 0;
}
public class ItemViewHolder extends RecyclerView.ViewHolder {
public TextView name, location, description;
public ImageView avatar, cardImage;
public ItemViewHolder(View view) {
super(view);
avatar = (ImageView)itemView.findViewById(R.id.post_avatar);
name = (TextView) itemView.findViewById(R.id.user_name);
location = (TextView) itemView.findViewById(R.id.card_location);
cardImage = (ImageView) itemView.findViewById(R.id.card_image);
description = (TextView) itemView.findViewById(R.id.card_text);
}
}
public class HeaderViewHolder extends RecyclerView.ViewHolder {
public TextView headerCity, headerCountry, headerTime, headerTemperature;
public ImageView headerImage;
public HeaderViewHolder(View view) {
super(view);
headerImage = (ImageView)itemView.findViewById(R.id.home_header_image);
headerCity = (TextView) itemView.findViewById(R.id.home_header_city);
headerCountry = (TextView) itemView.findViewById(R.id.home_header_country);
headerTime = (TextView) itemView.findViewById(R.id.home_header_time);
headerTemperature = (TextView) itemView.findViewById(R.id.home_header_temperature);
}
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if(viewType == TYPE_ITEM)
{
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_card, parent, false);
return new ItemViewHolder(itemView);
}
else if(viewType == TYPE_HEADER)
{
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.information_of_day, parent, false);
return new HeaderViewHolder(itemView);
}
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof HeaderViewHolder) {
HomeHeaderObject header = headerArrayList.get(position);
((HeaderViewHolder) holder).headerImage.setImageResource(header.getHomeHeaderImage());
((HeaderViewHolder) holder).headerCity.setText(header.getHomeHeaderCity());
((HeaderViewHolder) holder).headerCountry.setText(header.getHomeHeaderCountry());
((HeaderViewHolder) holder).headerTime.setText(header.getHomeHeaderTime());
((HeaderViewHolder) holder).headerTemperature.setText(header.getHomeHeaderTemperature());
}else if (holder instanceof ItemViewHolder) {
CardViewObject profiles = selectProfilesArrayList.get(position-1);
((ItemViewHolder) holder).avatar.setImageResource(profiles.getCardAvatar());
((ItemViewHolder) holder).name.setText(profiles.getCardName());
((ItemViewHolder) holder).location.setText(profiles.getCardLocation());
((ItemViewHolder) holder).cardImage.setImageResource(profiles.getCardImage());
((ItemViewHolder) holder).description.setText(profiles.getCardDescription());
}
}