[英]How to use Recyclerview in android eclipse
Please help me. 请帮我。 Am using Eclipse ADT for development.
我正在使用Eclipse ADT进行开发。 I am facing a problem and i am not able to fix.
我遇到问题,无法修复。 I tried lots of answers in this stackoverflow but no one give a right solution.
我在这个stackoverflow中尝试了很多答案,但是没有人给出正确的解决方案。 Let me explain my problem
让我解释一下我的问题
E:\\software\\adt-bundle-windows-x86_64-20140702\\adt-bundle-windows-x86_64-20140702\\sdk\\extras\\android\\support\\v7\\recyclerview E:\\ software \\ adt-bundle-windows-x86_64-20140702 \\ adt-bundle-windows-x86_64-20140702 \\ sdk \\ extras \\ android \\ support \\ v7 \\ recyclerview
After imported, right click on recyclerview project--> properties --> android tab (From left pane) ---> make checked isLibrary checkbox 导入后,右键单击recyclerview项目->属性-> android选项卡(从左窗格)->选中isLibrary复选框
Then causally, i write a code in my class which extends the fragment 然后因果,我在我的课堂上写了一段代码来扩展片段
public class FragmentTab1 extends Fragment { 公共类FragmentTab1扩展了Fragment {
View view;
RecyclerView mRecyclerView;
TimelineAdapter timelineAdapter;
// ListView listView;
// RecyclerView mRecyclerView;
// RecyclerView.LayoutManager mLayoutManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
try {
view = inflater.inflate(R.layout.fragmenttab1, container, false);
mRecyclerView = (RecyclerView) view
.findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(false);
mRecyclerView.setAdapter(new TimelineAdapter(getActivity()));
} catch (Exception e) {
// TODO: handle exception
Log.e("FragOne error ", "" + e.getMessage());
Log.e("FragOne error ", "" + e.getCause());
}
return view;
}
} }
I have written adapter class and am 100% sure there is no errors. 我已经编写了适配器类,并且100%确定没有错误。
When i am seeing the layout xml file then i am unble to see the recyclerview. 当我看到布局xml文件时,我无法看到recyclerview。 Please refer the image attchment below
请参考下面的图片附件
Please take a look about my xml file what i have written 请看看我写的xml文件
<FrameLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_grey"
tools:context=".LoginFollowUsers" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/letterimg"
android:scrollbars="vertical" />
</LinearLayout>
After i am importing recyclerview project from support/v7/recyclerview i am not able to see any file in src folder.. can any one share the recyclerview project 从support / v7 / recyclerview导入recyclerview项目后,我无法在src文件夹中看到任何文件..任何人都可以共享recyclerview项目
Please help me out form this issue 请帮我解决这个问题
Thanks in advance to all 在此先感谢所有人
You have to explicitly set LayoutManager for RecyclerView: 您必须为RecyclerView显式设置LayoutManager:
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity));
Without this RecyclerView will no run. 没有这个,RecyclerView将无法运行。
You need JDK 8
for new android library set JDK and JRE and try it will work.!!!! 您需要将
JDK 8
用于新的Android库集JDK和JRE,然后尝试使用它。
i had same issue but after installing JDK 8
it's resolved 我遇到了同样的问题,但是在安装
JDK 8
就解决了
You should add recylerView
library into your project. 您应该将
recylerView
库添加到您的项目中。 Right click on your project in your project explorer > Select properties > navigate to android in left pane > now click on ADD button in right pane > After clicking add button you should add recylerView
library. 在项目浏览器中右键单击您的项目>选择属性>在左窗格中导航到android>现在单击右窗格中的ADD按钮>单击添加按钮后,您应该添加
recylerView
库。
You need to add following code in your java file while defining recylerView
. 定义
recylerView
需要在Java文件中添加以下代码。
mRecyclerView = (RecyclerView) view
.findViewById(R.id.my_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(
getActivity()));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
You need to add card view to show the recycler view items.I am sending sample code.try it once. 您需要添加卡片视图以显示回收者视图项目。我正在发送示例代码。请尝试一次。
Import cardview project from this path
E:\\software\\adt-bundle-windows-x86_64-20140702\\adt-bundle-windows-x86_64-20140702\\sdk\\extras\\android\\support\\v7\\cardview E:\\ software \\ adt-bundle-windows-x86_64-20140702 \\ adt-bundle-windows-x86_64-20140702 \\ sdk \\ extras \\ android \\ support \\ v7 \\ cardview
RecyclerView recList = (RecyclerView) view.findViewById(R.id.cardList);
recList.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setOrientation(LinearLayoutManager.VERTICAL);
recList.setLayoutManager(llm);
ArrayList<MyBean> myListItems = new ArrayList<MyBean>();
for (int i = 0; i < 5; i++) {
myListItems.add(new MyBean("item:"+i));
}
MyRecycleAdapter adapter = new MyRecycleAdapter(myListItems);
recList.setAdapter(adapter);
public class MyRecycleAdapter extends RecyclerView.Adapter { 公共类MyRecycleAdapter扩展了RecyclerView.Adapter {
private List<MyBean> myItemsList;
public MyRecycleAdapter (List<MyBean> myItemsList) {
this.myItemsList = myItemsList;
}
@Override
public int getItemCount() {
return myItemsList.size();
}
@Override
public void onBindViewHolder(MyViewHolder viewHolder, int i) {
MyBean ci = myItemsList.get(i);
MyViewHolder.id.setText("" + ci.getId());
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.mycardview, viewGroup, false);
return new MyViewHolder(itemView);
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
protected TextView id;
public MyViewHolder(View v) {
super(v);
id = (TextView) v.findViewById(R.id.textView1);
}
}
} }
just take one textview. 只需一个textview。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.