одни и те же данные появляются во всем обзоре Recycler и увеличиваются позиции, но такие же данные появляются
в useradapter я записываю позицию и увеличение позиции, но данные в onbindviewholder такие же
useradapter
public class useradapter extends RecyclerView.Adapter<useradapter.CustomView> {
String nn = "m";
List<allusermodel> list1;
private Context context;
private LayoutInflater layoutInflater;
public useradapter(Context context, List<allusermodel> list1) {
Log.e("reached1", nn);
this.context = context;
this.list1 = list1;
}
@Override
public useradapter.CustomView onCreateViewHolder(final ViewGroup parent, final int viewType) {
Log.e("reached2", nn);
if (layoutInflater == null) {
layoutInflater = LayoutInflater.from(parent.getContext());
}
final Entrys newsBinding = Entrys.inflate(layoutInflater, parent, false);
// View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.innerlayout,parent,false);
return new CustomView(newsBinding);
}
@Override
public void onBindViewHolder(useradapter.CustomView holder,int position) {
Log.e("reached3", nn);
// News news = newsList.get(position);
// holder.desc.setText(news.getDesc());
allusermodel newsModel1 = list1.get(position);
// Log.e("list", String.valueOf(list1));
Log.e("nameeeee",newsModel1.getAll_user());
// Log.e("position", String.valueOf(position));
//Log.e("names",newsModel1.getAll_user());
holder.bind(newsModel1);
}
@Override
public int getItemCount() {
return list1.size();
}
public class CustomView extends RecyclerView.ViewHolder {
private Entrys newsBinding;
// public TextView title;
//TextView title, desc;
public CustomView(Entrys newsBinding) {
super(newsBinding.getRoot());
this.newsBinding = newsBinding;
Log.e("reached4", nn);
// title = (TextView)itemView.findViewById(R.id.titleval);
//desc =(TextView)itemView.findViewById(R.id.descval);
newsBinding.setRecyclerclick(new Presenters2() {
@Override
public void onclickListener() {
int pos = getAdapterPosition();
if (pos != RecyclerView.NO_POSITION) {
allusermodel clickedDataItem = list1.get(pos);
Intent intent = new Intent(context, messagelist.class);
intent.putExtra("clickid", clickedDataItem.getId());
context.startActivity(intent);
}
}
});
}
public void bind(allusermodel newsModel1)
{
Log.e("reached5", String.valueOf(newsModel1));
//String j = newsModel1.getAll_user();
// Log.e("bind",nn);
this.newsBinding.setAlluserentry(newsModel1);
}
public Entrys getNewsBinding() {
Log.e("reached6", nn);
return newsBinding;
}
}
}
1008 * Список пользователей *
public class userlist extends AppCompatActivity {
private static final String TAG = "userlist";
private RecyclerView recyclerView;
private LinearLayoutManager linearLayoutManager;
private DividerItemDecoration dividerItemDecoration;
private useradapter customAdapter;
private DataManager2 dataManger;
private List<allusermodel> newsList;
private RecyclerView.Adapter adapter;
String token2;
String URL1 = "https://chat.promactinfo.com/api/user";
private int userid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userlist);
SharedPreferences pref = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
token2 = pref.getString("sherdtoken", "");
Log.e("token", token2);
dataManger = new DataManager2(this);
recyclerView = (RecyclerView) findViewById(R.id.recycle);
/*recyclerView.setLayoutManager(new LinearLayoutManager(this));
newsList = new ArrayList<>();
customAdapter = new useradapter(this, newsList);
recyclerView.setAdapter(customAdapter);*/
newsList = new ArrayList<>();
getdata();
}
public void getdata() {
dataManger.sendVolleyRequest1(token2, userlist.this, new DataValue() {
@Override
public void setJsonDataResponse1(JSONArray response) {
allusermodel userModel = new allusermodel();
// newsList = new ArrayList<>();
for (int i = 0; i < response.length(); i++) {
try {
JSONObject jsonObject = response.getJSONObject(i);
// Log.e("final", String.valueOf(i));
// userid = jsonObject.getInt("id");
userModel.setId(jsonObject.getInt("id"));
// Log.e("getid", String.valueOf(jsonObject.getInt("id")));
userModel.setAll_user(jsonObject.getString("name"));
// Log.e("getname", String.valueOf(jsonObject.getString("name")));
newsList.add(userModel);
// Log.e("userlist", String.valueOf(newsList));
} catch (JSONException jsonDataResponse) {
Log.e("error", String.valueOf(jsonDataResponse));
}
}
adapter = new useradapter(getApplicationContext(),newsList);
linearLayoutManager = new LinearLayoutManager(getApplicationContext());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), linearLayoutManager.getOrientation());
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.addItemDecoration(dividerItemDecoration);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
@Override
public void setVolleyError1(VolleyError volleyError) {
Log.e("Volley", volleyError.toString());
}
});
}
}
allusermodel
public class allusermodel extends BaseObservable {
public int id;
public String all_user;
public allusermodel() {
}
public allusermodel(int id,String name ) {
this.id = id;
this.all_user = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAll_user() {
return all_user;
}
public void setAll_user(String all_user) {
this.all_user = all_user;
}
@Override
public String toString() {
return "allusermodel{" +
"id=" + id +
", all_user='" + all_user + '\'' +
'}';
}
}
userlist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mayurpancholi.chat_mvvm.userlist"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycle"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
innerlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data class ="Entrys">
<variable
name="alluserentry"
type="com.example.mayurpancholi.chat_mvvm.viewmodel.allusermodel"/>
<variable
name="recyclerclick"
type="com.example.mayurpancholi.chat_mvvm.interfaces.Presenters2"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:padding="10dp"
android:onClick="@{()->recyclerclick.onclickListener()}"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/titleval"
android:textSize="20dp"
android:text="@{alluserentry.all_user}"
android:textStyle="bold"
android:layout_marginTop="10dp"
/>
</LinearLayout>
</layout>
весь просмотрщик имеет те же данные, которые я ранее добавил в API
(Если я ввожу имя в записи, то это показывает предыдущую запись во всем recylerview
тогда, если я введу name1 в запись, то она покажет имя во всем recylerview)