Java 为什么列出Recyclerview在所有位置返回相同的项目?
在我的android应用程序中,我使用recycler视图显示项目 (注意:这不是一个重复的问题,因为我尝试了stackoverflow的许多答案,但没有找到解决方案。) 我的问题Java 为什么列出Recyclerview在所有位置返回相同的项目?,java,android,collections,android-recyclerview,Java,Android,Collections,Android Recyclerview,在我的android应用程序中,我使用recycler视图显示项目 (注意:这不是一个重复的问题,因为我尝试了stackoverflow的许多答案,但没有找到解决方案。) 我的问题 显示重复项目的回收器视图。单个项重复多次,即使它在源数据库中只出现一次 我检查了原因并注意到Adapter类中的List对象在所有迭代中返回相同的值。但将列表对象发送到具有唯一值的适配器类的片段 但只有在接收到列表对象后,适配器类才包含重复项 我尝试过的解决方案 我检查了Stackoverflow,并在适配器类中添
显示重复项目的回收器视图。单个项重复多次,即使它在源数据库中只出现一次 我检查了原因并注意到Adapter类中的List对象在所有迭代中返回相同的值。但将列表对象发送到具有唯一值的适配器类的片段 但只有在接收到列表对象后,适配器类才包含重复项 我尝试过的解决方案
- 我检查了Stackoverflow,并在适配器类中添加了getItemId(int位置)和getItemViewType(int位置),但没有解决方案
- 我检查了数据库和列表视图发送类都没有重复的项
InboxHostFragment.java=此类将列表对象发送到回收器视图的适配器类: 在上面的代码中,feedItemList返回重复的值,即使源clas Inboxfragment.java中的movieList列表包含唯一的值
请帮我解决这个问题。我在Stackoverflow中尝试了许多答案,但我找不到解决方案。我想不出这个问题。使用此代码
for (int i = 0; i < contact.length(); i++) {
JSONObject obj1 = contact.optJSONObject(i);
ListFeed movie = new ListFeed();
movie.getuserby(obj1.getString("userby"));
movie.resid(obj1.getString("reservation_id"));
movie.setresidinbox(obj1.getString("reservation_id"));
System.out.println("reservation iddgdsds" + obj1.getString("reservation_id"));
movie.setuserbys(obj1.getString("userby"));
movie.setuserto(obj1.getString("userto"));
movie.setid(obj1.getString("room_id"));
movie.getid1(obj1.getString("id"));
movie.userto(obj1.getString("userto"));
movie.isread(obj1.getString("isread"));
movie.userbyname(obj1.getString("userbyname"));
country_symbol = obj1.getString("currency_code");
Currency c = Currency.getInstance(country_symbol);
country_symbol = c.getSymbol();
movie.setsymbol(country_symbol);
movie.setTitle(obj1.getString("title"));
movie.setThumbnailUrl(obj1.getString("profile_pic"));
movie.setstatus(obj1.getString("status"));
movie.setcheckin(obj1.getString("checkin"));
movie.setcheckout(obj1.getString("checkout"));
movie.setcreated(obj1.getString("created"));
movie.guest(obj1.getString("guest"));
movie.userbyname(obj1.getString("username"));
movie.getprice(obj1.getString("price"));
String msg = obj1.getString("message");
msg = msg.replaceAll("<b>You have a new contact request from ", "");
msg = msg.replaceAll("</b><br><br", "");
msg = msg.replaceAll("\\w*\\>", "");
movie.message(msg);
movieList.add(movie);
System.out.println(movieList.get(i).message()); // returning unique value
}
for(int i=0;i”,”);
电影讯息(msg),;
movieList.add(电影);
System.out.println(movieList.get(i.message());//返回唯一值
}
声明ListFeed movie=newlistfeed()编码>进入for循环
并移除适配器。notifyDataSetChanged()代码>来自循环的
我认为这对您有帮助。使用此代码
for (int i = 0; i < contact.length(); i++) {
JSONObject obj1 = contact.optJSONObject(i);
ListFeed movie = new ListFeed();
movie.getuserby(obj1.getString("userby"));
movie.resid(obj1.getString("reservation_id"));
movie.setresidinbox(obj1.getString("reservation_id"));
System.out.println("reservation iddgdsds" + obj1.getString("reservation_id"));
movie.setuserbys(obj1.getString("userby"));
movie.setuserto(obj1.getString("userto"));
movie.setid(obj1.getString("room_id"));
movie.getid1(obj1.getString("id"));
movie.userto(obj1.getString("userto"));
movie.isread(obj1.getString("isread"));
movie.userbyname(obj1.getString("userbyname"));
country_symbol = obj1.getString("currency_code");
Currency c = Currency.getInstance(country_symbol);
country_symbol = c.getSymbol();
movie.setsymbol(country_symbol);
movie.setTitle(obj1.getString("title"));
movie.setThumbnailUrl(obj1.getString("profile_pic"));
movie.setstatus(obj1.getString("status"));
movie.setcheckin(obj1.getString("checkin"));
movie.setcheckout(obj1.getString("checkout"));
movie.setcreated(obj1.getString("created"));
movie.guest(obj1.getString("guest"));
movie.userbyname(obj1.getString("username"));
movie.getprice(obj1.getString("price"));
String msg = obj1.getString("message");
msg = msg.replaceAll("<b>You have a new contact request from ", "");
msg = msg.replaceAll("</b><br><br", "");
msg = msg.replaceAll("\\w*\\>", "");
movie.message(msg);
movieList.add(movie);
System.out.println(movieList.get(i).message()); // returning unique value
}
for(int i=0;i”,”);
电影讯息(msg),;
movieList.add(电影);
System.out.println(movieList.get(i.message());//返回唯一值
}
声明ListFeed movie=newlistfeed()编码>进入for循环
并移除适配器。notifyDataSetChanged()代码>来自循环的
我认为这对您有帮助。代码中的recyclerview在哪里?我不知道上面有什么,但请参阅的CustomAdapter类了解如何设置recyclerview!并查看片段以查看其调用方式。@Ragesh D Antony if(listFeed.guest().equals(“1”){holder.guest.setText(listFeed.guest()+activity.getResources().getString(R.string.guests));}else{holder.guest.setText(listFeed.guest()+activity.getResources().getString(R.string.guests));}在正确和错误的部分,您正在做同样的事情。您能告诉我们创建InboxHostAdapter“public InboxHostAdapter(上下文活动,ListfeedItemList,String标记)”的调用方代码吗。我想看看你是如何得到“feedItemList”的。这个问题是通过@SSALPHAX在下面的回答中提到的步骤解决的。谢谢你的回答你的代码里有回收视图吗?我不知道那是什么
for (int i = 0; i < contact.length(); i++) {
JSONObject obj1 = contact.optJSONObject(i);
ListFeed movie = new ListFeed();
movie.getuserby(obj1.getString("userby"));
movie.resid(obj1.getString("reservation_id"));
movie.setresidinbox(obj1.getString("reservation_id"));
System.out.println("reservation iddgdsds" + obj1.getString("reservation_id"));
movie.setuserbys(obj1.getString("userby"));
movie.setuserto(obj1.getString("userto"));
movie.setid(obj1.getString("room_id"));
movie.getid1(obj1.getString("id"));
movie.userto(obj1.getString("userto"));
movie.isread(obj1.getString("isread"));
movie.userbyname(obj1.getString("userbyname"));
country_symbol = obj1.getString("currency_code");
Currency c = Currency.getInstance(country_symbol);
country_symbol = c.getSymbol();
movie.setsymbol(country_symbol);
movie.setTitle(obj1.getString("title"));
movie.setThumbnailUrl(obj1.getString("profile_pic"));
movie.setstatus(obj1.getString("status"));
movie.setcheckin(obj1.getString("checkin"));
movie.setcheckout(obj1.getString("checkout"));
movie.setcreated(obj1.getString("created"));
movie.guest(obj1.getString("guest"));
movie.userbyname(obj1.getString("username"));
movie.getprice(obj1.getString("price"));
String msg = obj1.getString("message");
msg = msg.replaceAll("<b>You have a new contact request from ", "");
msg = msg.replaceAll("</b><br><br", "");
msg = msg.replaceAll("\\w*\\>", "");
movie.message(msg);
movieList.add(movie);
System.out.println(movieList.get(i).message()); // returning unique value
}