// Ma'lumotlar ro'yxati
List userList = new ArrayList<>();
userList.add(new User("Qodirov ", "Isomiddin", 21, "Yozyovon"));
// RecyclerViewni aniqlash va sozlash
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// Adapterni o'rnating
UserAdapter userAdapter = new UserAdapter(userList);
recyclerView.setAdapter(userAdapter);
}
}
User.java:
public class User {
private String lastName;
private String firstName;
private int age;
private String birthplace;
public User(String lastName, String firstName, int age, String birthplace) {
this.lastName = lastName;
this.firstName = firstName;
this.age = age;
this.birthplace = birthplace;
}
public String getLastName() {
return lastName;
}
public String getFirstName() {
return firstName;
}
public int getAge() {
return age;
}
public String getBirthplace() {
return birthplace;
}
}
UserAdapter.java:
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
Do'stlaringiz bilan baham: |