Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing an android app that will have a recyclerview in fragment but am having errors implementing it in the code.

Error "linealayoutmanager (android.content.context) in linealayoutmanager cannot be applied to (packagename.FragmentA)"

See my code below

public class FragmentA extends Fragment {

private ListView listView;
private MyAdapter myAdapter;
Context context;


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


//Part of cardview code starts here
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerList);
LinearLayoutManager llm = new LinearLayoutManager(this);//ERROR HERE
llm.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(llm);

recyclerView.setAdapter(new MyRecyclerAdapter(generatePalettes()));

recyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
switch( position )
{
case 0: Intent myIntent = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 1: Intent myIntent1 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 2: Intent myIntent2 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 3: Intent myIntent3 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 4: Intent myIntent4 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 5: Intent myIntent5 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 6: Intent myIntent6 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 7: Intent myIntent7 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 8: Intent myIntent8 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;
case 9: Intent myIntent9 = new Intent(FragmentA.this.getActivity(), AboutFounder.class);
break;

}
}
})
);
//Ends here


return rootView;
}

//Remaining part of CardView Starts Here
private ArrayList<palette> generatePalettes() {
ArrayList<palette> palettes = new ArrayList<palette>();
palettes.add(new Palette("PUNCH", R.mipmap.ic_launcher));
palettes.add(new Palette("TRIBUNE", R.mipmap.ic_launcher));
palettes.add(new Palette("DAILYPOST", R.mipmap.ic_launcher));
palettes.add(new Palette("THE SUN", R.mipmap.ic_launcher));
palettes.add(new Palette("THE GUARDIAN", R.mipmap.ic_launcher));
palettes.add(new Palette("THE NATION", R.mipmap.ic_launcher));
palettes.add(new Palette("THISDAY LIVE", R.mipmap.ic_launcher));
palettes.add(new Palette("PREMIUM TIMES", R.mipmap.ic_launcher));
palettes.add(new Palette("SAHARA REPORTS", R.mipmap.ic_launcher));
palettes.add(new Palette("VANGUARD", R.mipmap.ic_launcher));
return palettes;
}

}
Kindly help
Posted

1 solution

See http://developer.android.com/guide/components/fragments.html[^] for how to implement a fragment correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900