linealayoutmanager中的linealayoutmanager(android.content.context)无法应用于(packagename.FragmentA) [英] linealayoutmanager (android.content.context) in linealayoutmanager cannot be applied to (packagename.FragmentA)

查看:107
本文介绍了linealayoutmanager中的linealayoutmanager(android.content.context)无法应用于(packagename.FragmentA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,它将在片段中有一个recyclerview但是在代码中实现它时出错。



错误linealayoutmanager(android.content。 linealayoutmanager中的上下文不能应用于(packagename.FragmentA)



请参阅下面的代码



公共类FragmentA扩展片段{



私有ListView listView;

私有MyAdapter myAdapter;

上下文上下文; < br $>




@Override

public查看onCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState){

查看rootView = inflater.inflate(R.layout.fragment_a,container,false);





//部分cardview代码从这里开始

RecyclerView recyclerView =(RecyclerView)rootView.findViewById(R.id.recyclerList);

LinearLayoutManager llm = new LinearL ayoutManager(this); //错误在这里

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;

案例1:意图myIntent1 =新意图(FragmentA.this.getActivity(),AboutFounder.class);

休息;

案例2:意图myIntent2 =新意图(FragmentA.this.getActivity(),AboutFounder.class);

休息;

情况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 );

休息;

案例6:意图myIntent6 =新意图(FragmentA.this.getActivity(),AboutFounder.class);

休息;

案例7:意图myIntent7 =新意图(FragmentA.thi s.getActivity(),AboutFounder.class);

break;

case 8:Intent myIntent8 = new Intent(FragmentA.this.getActivity(),AboutFounder.class) ;

休息;

案例9:意图myIntent9 =新意图(FragmentA.this.getActivity(),AboutFounder.class);

break ;



}

}

})

);

//在这里结束





返回rootView;

}



// CardView的剩余部分从这里开始

private ArrayList< palette> generatePalettes(){

ArrayList< palette> palettes = new ArrayList< palette>();

palettes.add(new Palette(PUNCH,R.mipmap.ic_launcher));

palettes.add(new调色板(TRIBUNE,R.mipmap.ic_launcher));

palettes.add(新调色板(DAILYPOST,R.mipmap.ic_launcher));

调色板.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(新调色板(PREMIUM TIMES,R.mipmap.ic_launcher));

palettes.add(新调色板(SAHARA REPORTS) ,R.mipmap.ic_launcher));

palettes.add(new Palette(VANGUARD,R.mipmap.ic_launcher));

返回调色板;

}



}

请帮助

解决方案

请参阅 http://developer.android.com/guide/components/fragments.html [ ^ ]了解如何正确实现片段。

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

解决方案

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


这篇关于linealayoutmanager中的linealayoutmanager(android.content.context)无法应用于(packagename.FragmentA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆