500px / greedo-layout-for-android

Full aspect ratio grid LayoutManager for Android's RecyclerView
MIT License
1.64k stars 156 forks source link

setMaxRowHeight, IMAGES, index #22

Open sagarpatel288 opened 8 years ago

sagarpatel288 commented 8 years ago

can not resolve setMaxRowHeight and index. I am using in fragment.

sagarpatel288 commented 8 years ago

Tried to solve by invalidate cache and restart! But it is still there!

JVillella commented 8 years ago

I'm not understanding the problem. setMaxRowHeight(int) isn't working for you? What is the current behaviour? How/where are you calling it? A code snippet and/or screenshot may also help.

eshkoliGilad commented 8 years ago

I think what he says is that he the IDE cannot resolve setMaxRowHeight. Probably can't import the necessary classes.

Please post some code in order to help or tell us what you did.

sagarpatel288 commented 8 years ago

Below is the line where android studio cannot resolve that method:

layoutManager.setMaxRowHeight(true);

Below is the complete fragment. I have included import class as well. At layout manager, where i tried to set its Maximum row height using layoutmanager.setMaxRowHeight, android studio says it cannot resolve that method. Also consider that i am completely new in programming, coding, android developement so there are chances that i've screwed up or messed up with things!

import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fivehundredpx.greedolayout.GreedoLayoutManager;
import com.fivehundredpx.greedolayout.GreedoSpacingItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link OneFragment.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the factory method to
 * create an instance of this fragment.
 */
public class OneFragment extends Fragment {

    private OnFragmentInteractionListener mListener;

    public OneFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Initialize items

        List<ModelData> rowListItem = getAllItemList();

        // Create adapter passing in the sample user data

        RvAdapter adapter = new RvAdapter(rowListItem, this.getActivity());

        RecyclerView.LayoutManager layoutManager = new GreedoLayoutManager(adapter);

        // Lookup the recyclerview in activity layout

        View rootView = inflater.inflate(R.layout.fragment_one, container, false);

        RecyclerView rView = (RecyclerView) rootView.findViewById(R.id.recycler_view);

        // Set layout manager to position the items

        rView.setLayoutManager(layoutManager);

        // some recommended optimization!

        rView.setHasFixedSize(true);

        // Attach the adapter to the recyclerview to populate items

        rView.setAdapter(adapter);

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        int maxRowHeight = metrics.heightPixels / 3;
        layoutManager.setMaxRowHeight(true);

        int spacing = com.example.android.platform2.MeasUtils.dpToPx(4, this.getActivity());
        rView.addItemDecoration(new GreedoSpacingItemDecoration(spacing));

        // Inflate the layout for this fragment

        return rootView;
    }

    @Override
    public String toString() {
        return "Users";
    }

    private List<ModelData> getAllItemList() {

        List<ModelData> allItems = new ArrayList<>();
        allItems.add(new ModelData("Dos", "Live and let others to live", R.drawable.dos));
        allItems.add(new ModelData("13", "Eternal Joy", R.drawable.thirteen));
        allItems.add(new ModelData("Deva", "Details", R.drawable.deva));
        allItems.add(new ModelData("Rathod", "Details", R.drawable.bhavesh));
        allItems.add(new ModelData("Das", "Details", R.drawable.dhruvin));
        allItems.add(new ModelData("Het", "Details", R.drawable.het));
        allItems.add(new ModelData("Me", "Details", R.drawable.me));
        allItems.add(new ModelData("76", "Details", R.drawable.sevensix));
        allItems.add(new ModelData("Pruthvi", "Details", R.drawable.pruthvi));

        return allItems;
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}