how to add like button in Recyclerview in android - java

I am a new application developer android app and need some help Please.
I need to know how to add the like button inside (Recyclerview) linked to a database (Mysql) and connect through a Volley library to save all user likes.And see how many likes each topic has.
An example that is in the picture..
I need to add it to this attached project.
MainActivity
public class MainActivity extends AppCompatActivity {
List<RecyclerViewData> recyclerViewDataList;
RecyclerView recyclerView;
private RVAdapter rvAdapter;
private static final String TAG="apple";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Employee List");
recyclerViewDataList=new ArrayList<>();
recyclerView=findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);
MakeVolleyConnection();
}
private void MakeVolleyConnection() {
recyclerViewDataList = new ArrayList<>();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
"http://10.0.13.45/v/parsing.php", null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray dataArray = response.getJSONArray("data");
for (int i = 0; i < dataArray.length(); i++) {
JSONObject userData = dataArray.getJSONObject(i);
RecyclerViewData recyclerViewData = new RecyclerViewData();
recyclerViewData.setId(userData.getInt("id"));
recyclerViewData.setFirstname(userData.getString("first_name"));
recyclerViewData.setLastname(userData.getString("last_name"));
recyclerViewData.setAvatar(userData.getString("avatar"));
recyclerViewDataList.add(recyclerViewData);
}
rvAdapter = new RVAdapter(recyclerViewDataList, MainActivity.this);
recyclerView.setAdapter(rvAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, ""+error.networkResponse,Toast.LENGTH_SHORT).show();
}
});
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest);
}
}
MySingleton
public class MySingleton {
private static MySingleton mInstance;
private RequestQueue mRequestQueue;
private static Context mContext;
private MySingleton(Context context){
// Specify the application context
mContext = context;
// Get the request queue
mRequestQueue = getRequestQueue();
}
public static synchronized MySingleton getInstance(Context context){
// If Instance is null then initialize new Instance
if(mInstance == null){
mInstance = new MySingleton(context);
}
// Return MySingleton new Instance
return mInstance;
}
public RequestQueue getRequestQueue(){
// If RequestQueue is null the initialize new RequestQueue
if(mRequestQueue == null){
mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
}
// Return RequestQueue
return mRequestQueue;
}
public<T> void addToRequestQueue(Request<T> request){
// Add the specified request to the request queue
getRequestQueue().add(request);
}
}
RecyclerViewData
public class RecyclerViewData {
private int id;
private String firstname;
private String lastname;
private String avatar;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
}
RVAdapter
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.RVHOLDER> {
List<RecyclerViewData> recyclerViewDataList;
Context mContext;
// Constructor with List and Context which we'll pass from RecyclerView Activity after a connection to Volley. And application context for the listener that we'll implement this later.
public RVAdapter(List<RecyclerViewData> recyclerViewDataList, Context mContext) {
this.recyclerViewDataList = recyclerViewDataList;
this.mContext = mContext;
}
// Override the method onCreateViewHolder, which will call the custom view holder that needs to be initialized. We specify the layout that each item to be used, so we can achieve this using Layout Inflator to inflate the layout and passing the output to constructor of custom ViewHolder.
#NonNull
#Override
public RVHOLDER onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(mContext).inflate(R.layout.adapter_layout, viewGroup, false);
RVHOLDER rvholder = new RVHOLDER(itemView);
return rvholder;
}
//onBindViewHolder is for specifying the each item of RecyclerView. This is very similar to getView() method on ListView. In our example, this is where you need to set the user's id, name and image.
#Override
public void onBindViewHolder(#NonNull RVHOLDER rvholder, int i) {
rvholder.id.setText("User id is "+recyclerViewDataList.get(i).getId());
rvholder.first_name.setText(recyclerViewDataList.get(i).getFirstname() + " " + recyclerViewDataList.get(i).getLastname());
Picasso.get().load(recyclerViewDataList.get(i).getAvatar()).into(rvholder.avatar);
}
//We need to return the size for RecyclerView as how long a RecyclerView is, Our data is in list so passing data.size() will return the number as long as we have.
#Override
public int getItemCount() {
return recyclerViewDataList.size();
}
//This is CustomView holder that we had discuss it earlier above and inflated it in onCreateView() method. This constructor links with the xml to set the data, which we set into onBindViewHolder().
class RVHOLDER extends RecyclerView.ViewHolder {
TextView id;
private TextView first_name;
private ImageView avatar;
public RVHOLDER(#NonNull View itemView) {
super(itemView);
id = itemView.findViewById(R.id.id);
first_name = itemView.findViewById(R.id.firstname_lastname);
avatar = itemView.findViewById(R.id.avatar);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="16dp"
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/firstname_lastname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="#+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
<?php
$con=mysqli_connect("localhost","root","root","test");
$sql="SELECT * FROM testtable";
$result=mysqli_query($con,$sql);
$data=array();
while($row=mysqli_fetch_assoc($result)){
$data["data"][]=$row;
}
header('Content-Type:Application/json');
echo json_encode($data);
?>

#Override
public void onBindViewHolder(#NonNull RVHOLDER rvholder, int i) {
rvholder.id.setText("User id is "+recyclerViewDataList.get(i).getId());
rvholder.first_name.setText(recyclerViewDataList.get(i).getFirstname() + " " +
recyclerViewDataList.get(i).getLastname());
Picasso.get().load(recyclerViewDataList.get(i).getAvatar()).into(rvholder.avatar);
if()
}
if (recyclerViewDataList.get(i).getLiked()) {
// liked image
Picasso.get().load(gContextCompat.getDrawable(getActivity(), R.drawable.liked);).into(rvholder.like);
} else {
// without like image
Picasso.get().load(gContextCompat.getDrawable(getActivity(), R.drawable.not_like);).into(rvholder.like);
}
Add like boolean variable in RecyclerViewData Class. Add getter and setter of it. Add two drawables in drawable folder for Like and Not_like. Then Add this logic. Hope this will help. Thanks

#Override
public void onBindViewHolder(#NonNull RVHOLDER rvholder, int i) {
rvholder.id.setText("User id is "+recyclerViewDataList.get(i).getId());
rvholder.first_name.setText(recyclerViewDataList.get(i).getFirstname() + " " + recyclerViewDataList.get(i).getLastname());
Picasso.get().load(recyclerViewDataList.get(i).getAvatar()).into(rvholder.avatar);
Picasso.get().load(gContextCompat.getDrawable(getActivity(), if(recyclerViewDataList.get(i).getLiked())R.drawable.liked else R.drawable.not_like).into(rvholder.like);
}

Related

How to pass Multiple selected checkbox value to the server using api in android?

I have a "Service" table in the database and I get the services using adapter class for service selection in the checkbox. It shows the service with a checkbox. I want to place the order which is selected by customer through checkbox. I need to pass the selected checkbox data to Api. But how to pass multiple checked checkbox values to the server?? Help me.
Here is my code
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn_get"
android:layout_width="91dp"
android:layout_height="38dp"
android:text="Place Order"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/recycler_view"
app:layout_constraintStart_toStartOf="#+id/recycler_view"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.72"
tools:ignore="MissingConstraints" />
Service.java
public class Service {
#SerializedName("laundry_service_id")
#Expose
String laundryServiceId;
#SerializedName("laundry_service_name")
#Expose
String laundryServiceName;
#SerializedName("laundry_service_short_form")
#Expose
String laundryServiceShortForm;
#SerializedName("laundry_order_status_id")
#Expose
String laundryOrderStatusId;
#SerializedName("laundry_service_create_by")
#Expose
String laundryServiceCreateBy;
#SerializedName("laundry_service_join_date")
#Expose
String laundryServiceJoinDate;
public Service(String laundryServiceId, String laundryServiceName,
String laundryServiceShortForm, String laundryOrderStatusId,
String laundryServiceCreateBy, String laundryServiceJoinDate) {
this.laundryServiceId = laundryServiceId;
this.laundryServiceName = laundryServiceName;
this.laundryServiceShortForm = laundryServiceShortForm;
this.laundryOrderStatusId = laundryOrderStatusId;
this.laundryServiceCreateBy = laundryServiceCreateBy;
this.laundryServiceJoinDate = laundryServiceJoinDate;
}
public String getLaundryServiceId() {
return laundryServiceId;
}
public void setLaundryServiceId(String laundryServiceId) {
this.laundryServiceId = laundryServiceId;
}
public String getLaundryServiceName() {
return laundryServiceName;
}
public void setLaundryServiceName(String laundryServiceName) {
this.laundryServiceName = laundryServiceName;
}
public String getLaundryServiceShortForm() {
return laundryServiceShortForm;
}
public void setLaundryServiceShortForm(String laundryServiceShortForm) {
this.laundryServiceShortForm = laundryServiceShortForm;
}
public String getLaundryOrderStatusId() {
return laundryOrderStatusId;
}
public void setLaundryOrderStatusId(String laundryOrderStatusId) {
this.laundryOrderStatusId = laundryOrderStatusId;
}
public String getLaundryServiceCreateBy() {
return laundryServiceCreateBy;
}
public void setLaundryServiceCreateBy(String laundryServiceCreateBy) {
this.laundryServiceCreateBy = laundryServiceCreateBy;
}
public String getLaundryServiceJoinDate() {
return laundryServiceJoinDate;
}
public void setLaundryServiceJoinDate(String laundryServiceJoinDate) {
this.laundryServiceJoinDate = laundryServiceJoinDate;
}
}
ServiceAdapter.java
public class ServiceAdapter extends RecyclerView.Adapter<ServiceAdapter.ViewHolder> {
private static List<Integer> mSelectedItemsIds;
List<Service> serviceList;
//private List<Integer> mSelectedItemsIds;
Context context;
public ServiceAdapter(List<Service> serviceList, Context context) {
this.serviceList = serviceList;
this.context = context;
mSelectedItemsIds = new ArrayList<>();
}
public static List<Integer> getSelectedIds() {
return mSelectedItemsIds;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.service_layout,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, final int position) {
final Service serviceClass = serviceList.get(position);
holder.chkbox.setText(serviceClass.getLaundryServiceName());
holder.chkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
mSelectedItemsIds.add(position);
}else{
mSelectedItemsIds.remove(position);
}
}
});
}
#Override
public int getItemCount() {
return serviceList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
CheckBox chkbox;
public ViewHolder(#NonNull View itemView) {
super(itemView);
chkbox=itemView.findViewById(R.id.chkbox);
}
}
}
CheckboxActivity.java
public class CheckboxActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private List<Service> serList;
CheckBox checkBox;
int id;
Button btn_get;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checkbox);
checkBox = findViewById(R.id.chkbox);
btn_get = findViewById(R.id.btn_get);
recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
LinearLayoutManager LayoutManager = new LinearLayoutManager(CheckboxActivity.this,
LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(LayoutManager);
btn_get.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
viewService();
}
});
Call<List<Service>>call = RetrofitClient
.getInstance()
.getApi()
.getServices();
call.enqueue(new Callback<List<Service>>() {
#Override
public void onResponse(Call<List<Service>> call, Response<List<Service>> response) {
serList = response.body();
ServiceAdapter serviceAdapter = new ServiceAdapter(serList,CheckboxActivity.this);
recyclerView.setAdapter(serviceAdapter);
id = serList.size();
Toast.makeText(CheckboxActivity.this,"Get the services"+id,Toast.LENGTH_SHORT).show();
}
#Override
public void onFailure(Call<List<Service>> call, Throwable t) {
Toast.makeText(CheckboxActivity.this,"Try It" +
t.getMessage(),Toast.LENGTH_SHORT).show();
System.out.println(t.getMessage());
}
});
}
private void viewService() {
List<Integer> selectedid = ServiceAdapter.getSelectedIds();
//Log.d("List","=");
Toast.makeText(CheckboxActivity.this,"Clicked"+selectedid,Toast.LENGTH_SHORT).show();
for (int i = 0; i < selectedid.size(); i++) {
int chk = selectedid.get(i);
if (checkBox.isChecked()) {
String ch = checkBox.getText().toString();
Toast.makeText(CheckboxActivity.this,"Data"+ch,Toast.LENGTH_SHORT).show();
}
}
}
}
Api.java
#FormUrlEncoded
#POST("place_id.php")
Call<OrderResponse> place(
#Field("list") List<Integer> selectedid);
I tried the above code. Service.java class I get all service responses to show in recyclerview with a checkbox. Now I want to pass the selected checkbox value to the server. Please help me.
In your adapter class you are adding the position to the list mSelectedItemIds.
mSelectedItemsIds.add(position);
What you should be doing is adding the field from an object of Service class into that list. So let's say you want to pass the laundryServiceIds of the selected checkboxes to the server. Then, in that case you should do something like this:
In your adapter, change the type of list item to String:
private static List<Integer> mSelectedItemsIds;
In your adapter's onBindViewHolder :
if(isChecked){
mSelectedItemsIds.add(serviceClass.getLaundryServiceId());
}else{
mSelectedItemsIds.remove(serviceClass.getLaundryServiceId());
}
And then pass ServiceAdapter.getSelectedIds() to the server when you want.
I hope this solves your problem, if there's any confusion then feel free to comment.

Card View not appearing in RecyclerView

I'm building an app that connects to a REST API and retrieves all the Employees in a Database. The app uses a RecyclerView to display all the Employees that are brought back in a CardView. The problem is nothing appears in the RecyclerView, and there is data that is being returned from the REST API.
It is an Android application, built in Java, using Pie for the OS. The project was created using the Basic Activity Template.
My Activity Class
public class ViewAllEmployees extends AppCompatActivity {
private List<Employee> employees;
private RecyclerView rcView;
private EmployeeAdapter adapter;
private Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_all_employees);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
context = this;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
FetchEmployeesTask async = new FetchEmployeesTask(new AsyncResponse() {
#Override
public void processFinished(List<Employee> output) {
Log.i("Async", "Finished");
}
});
async.execute();
rcView = findViewById(R.id.rcView);
adapter = new EmployeeAdapter(context, employees);
rcView.setAdapter(adapter);
rcView.setLayoutManager(new LinearLayoutManager(context));
}
private class FetchEmployeesTask extends AsyncTask<Void, Void, List<Employee>> {
public AsyncResponse delegate = null;
public FetchEmployeesTask(AsyncResponse asyncResponse){
delegate = asyncResponse;
}
#Override
protected List<Employee> doInBackground(Void... voids) {
return new APIHelper().fetchItems();
}
#Override
protected void onPostExecute(List<Employee> items) {
employees = items;
delegate.processFinished(items);
}
}
public interface AsyncResponse{
void processFinished(List<Employee> output);
}
}
The Employee Adapter for the RecyclerView
public class EmployeeAdapter extends RecyclerView.Adapter<EmployeeAdapter.EmployeeViewHolder> {
private List<Employee> employees;
private final LayoutInflater mInflater;
private Context context;
public int position;
public EmployeeAdapter(Context context, List<Employee> employeeList){
this.context = context;
employees = new ArrayList<>();
mInflater = LayoutInflater.from(context);
employees = employeeList;
}
#NonNull
#Override
public EmployeeViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View mItemView = mInflater.inflate(R.layout.employee_card, viewGroup, false);
return new EmployeeViewHolder(mItemView, this);
}
#Override
public void onBindViewHolder(#NonNull EmployeeViewHolder employeeViewHolder, int i) {
Employee empl = employees.get(i);
employeeViewHolder.name.setText(empl.firstName + empl.lastName);
employeeViewHolder.department.setText(empl.department);
}
#Override
public int getItemCount() {
return employees == null ? 0 : employees.size();
}
class EmployeeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public final TextView name;
public final TextView department;
private EmployeeAdapter adapter;
private final CardView card;
public EmployeeViewHolder(View itemView, EmployeeAdapter adapter) {
super(itemView);
name = itemView.findViewById(R.id.txtName);
department = itemView.findViewById(R.id.txtDepartment);
card = itemView.findViewById(R.id.cv);
itemView.setOnClickListener(this);
this.adapter = adapter;
}
#Override
public void onClick(View view) {
}
}
}
The APIHelper class
public class APIHelper {
private static final String ENDPOINT = "ENDPOINTADDRESS";
private static final String TAG = "APIHelper";
public byte[] getUrlBytes(String urlSpec) throws IOException{
URL url = new URL(urlSpec);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
try{
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = connection.getInputStream();
if(connection.getResponseCode() != HttpURLConnection.HTTP_OK){
return null;
}
int bytesRead = 0;
byte[] buffer = new byte[1024];
while((bytesRead = in.read(buffer)) > 0){
out.write(buffer, 0, bytesRead);
}
out.close();
return out.toByteArray();
}
finally {
connection.disconnect();
}
}
public String getUrlString(String urlSpec) throws IOException{
return new String((getUrlBytes(urlSpec)));
}
private void parseItems(List<Employee> employees, JSONArray jsonBody) throws IOException, JSONException {
JSONArray employeeArray = jsonBody;
for(int i = 0; i < employeeArray.length(); i++){
JSONObject jsonEmployee = employeeArray.getJSONObject(i);
JSONObject job = jsonEmployee.getJSONObject("Job");
Employee emp = new Employee();
//emp.setDepartment(jsonEmployee.getString("DepartmentId"));
emp.setEmail(jsonEmployee.getString("EmailAddress"));
emp.setEmployeeID(jsonEmployee.getString("EmployeeID"));
emp.setFirstName(jsonEmployee.getString("FirstName"));
emp.setLastName(jsonEmployee.getString("LastName"));
emp.setMiddleInitial(jsonEmployee.getString("MiddleInitial"));
emp.setPosition(job.getString("JobTitle"));
emp.setWorkNumber(jsonEmployee.getString("WorkNumber"));
employees.add(emp);
}
}
public List<Employee> fetchItems(){
List<Employee> employees = new ArrayList<>();
try{
String url = Uri.parse(ENDPOINT).buildUpon().build().toString();
String jsonString = getUrlString(url);
Log.i(TAG, "Received JSON: " + jsonString);
JSONArray jsonBody = new JSONArray(jsonString);
parseItems(employees, jsonBody);
}
catch (IOException ioe){
Log.e(TAG, "Failed to fetch items", ioe);
}
catch (JSONException je){
Log.e(TAG, "Failed to parse json:", je);
}
return employees;
}
The Layout for ViewAllEmployees
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".ViewAllEmployees"
tools:showIn="#layout/activity_view_all_employees">
<android.support.v7.widget.RecyclerView
android:id="#+id/rcView"
android:layout_width="395dp"
android:layout_height="659dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
The Card View that is in the Recyclerview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="16dp">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Name"/>
<TextView
android:id="#+id/txtDepartment"
android:layout_width="match_parent"
android:layout_height="127dp"
android:layout_below="#+id/txtName"
android:layout_alignEnd="#+id/txtName"
android:layout_marginTop="-142dp"
android:layout_marginEnd="0dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
When the App is run, the RecyclerView should populate with CardViews that display an Employees name and their Department. However, it currently displays nothing.
You have to notify your adapter after populating your array list. Initialize your employee array list variable,then Do:
private class FetchEmployeesTask extends AsyncTask<Void, Void, List<Employee>> {
public AsyncResponse delegate = null;
public FetchEmployeesTask(AsyncResponse asyncResponse){
delegate = asyncResponse;
}
#Override
protected List<Employee> doInBackground(Void... voids) {
return new APIHelper().fetchItems();
}
#Override
protected void onPostExecute(List<Employee> items) {
employees.addAll(items);
adapter.notifyDataSetChanged();
delegate.processFinished(items);
}
}
FetchEmployeesTask async = new FetchEmployeesTask(new AsyncResponse() {
#Override
public void processFinished(List<Employee> output) {
Log.i("Async", "Finished");
employees.addAll(items);
adapter.notifyDataSetChanged();
}
});

Image click of RecyclerView

I know that there are already questions on this, but the format which I follow for my code is different so I am unable to find the answer to the question.
When I click on my RecyclerView item which includes TextView and ImageView, I want to show the image in a DetailActivity.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="pritish.sawant.com.photogallery.MainActivity">
</FrameLayout>
fragment_photo_gallery.xml
<RelativeLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="pritish.sawant.com.photogallery.PhotoGalleryFragment">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:id="#+id/recyclerview"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/loading_indicator"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_centerInParent="true"/>
</RelativeLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="Hi" />
<ImageView
android:id="#+id/imageview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:src="#drawable/image1">
</ImageView>
</LinearLayout>
activity_detail.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="pritish.sawant.com.photogallery.DetailActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/detailimageview"
tools:src="#drawable/image1"/>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private FragmentManager fragmentManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Photo Gallery");
fragmentManager=getSupportFragmentManager();
Fragment fragment=fragmentManager.findFragmentById(R.id.framelayout);
if(fragment==null){
fragment=new PhotoGalleryFragment();
fragmentManager.beginTransaction().add(R.id.framelayout,fragment).commit();
}
}
}
Photo.java
package pritish.sawant.com.photogallery;
public class Photo {
private String title;
private String author;
private String authorId;
private String link;
private String image;
private String tag;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getAuthorId() {
return authorId;
}
public void setAuthorId(String authorId) {
this.authorId = authorId;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
#Override
public String toString() {
return "Photo{" +
"title='" + title + '\'' +
", author='" + author + '\'' +
", authorId='" + authorId + '\'' +
", link='" + link + '\'' +
", image='" + image + '\'' +
", tag='" + tag + '\'' +
'}';
}
}
FlickrFetchr.java
package pritish.sawant.com.photogallery;
import android.net.Uri;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class FlickrFetchr {
private static final String TAG = "FlickrFetchr";
private List<Photo> photoList = null;
private String baseUrl="https://api.flickr.com/services/feeds/photos_public.gne";
public String getData(String url){
BufferedReader bufferedReader=null;
try {
URL url1=new URL(url);
HttpURLConnection httpURLConnection=(HttpURLConnection)url1.openConnection();
StringBuilder stringBuilder=new StringBuilder();
bufferedReader=new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String line;
while ((line=bufferedReader.readLine())!=null){
stringBuilder.append(line+"\n");
}
return stringBuilder.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
finally {
if(bufferedReader!=null){
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
}
private String buildURL(String searchPhoto, String lang, boolean match){
return Uri.parse(baseUrl).buildUpon().appendQueryParameter("tags", searchPhoto)
.appendQueryParameter("tagmode", match ? "ALL" : "ANY")
.appendQueryParameter("format", "json")
.appendQueryParameter("lang", lang)
.appendQueryParameter("nojsoncallback", "1").build().toString();
}
public List<Photo> fetchPhotos(String searchPhoto,String language,boolean matchAll){
String url=buildURL(searchPhoto,language,matchAll);
return downloadGalleyItem(url);
}
//To receive the json format
public List<Photo> downloadGalleyItem(String url){
photoList=new ArrayList<>();
Photo photo=new Photo();
String jsonString=getData(url);
try {
JSONObject jsonObject=new JSONObject(jsonString);
JSONArray jsonArray=jsonObject.getJSONArray("items");
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject1=jsonArray.getJSONObject(i);
photo.setTitle(jsonObject1.getString("title"));
photo.setAuthor(jsonObject1.getString("author"));
photo.setAuthorId(jsonObject1.getString("author_id"));
photo.setTag(jsonObject1.getString("tags"));
JSONObject jsonMedia =jsonObject1.getJSONObject("media");
String imageUrl=jsonMedia.getString("m");
photo.setImage(jsonMedia.getString("m"));
//we are changing _m to _b so that when image is tapped we get biigger image
photo.setLink(imageUrl.replaceAll("_m.","_b."));
photoList.add(photo);
}
} catch (Exception e) {
e.printStackTrace();
}
return photoList;
}
}
RecyclerItemClickListener.java
public class RecyclerItemClickListener extends RecyclerView.SimpleOnItemTouchListener {
private static final String TAG = "RecyclerItemClickListen";
interface OnRecyclerClickListener{
void onItemClick(View view,int position);
void onItemLongClick(View view,int position);
}
private final OnRecyclerClickListener listener;
private final GestureDetectorCompat gestureDetectorCompat;
public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, final OnRecyclerClickListener listener) {
this.listener = listener;
gestureDetectorCompat=new GestureDetectorCompat(context,new GestureDetector.SimpleOnGestureListener(){
#Override
public boolean onSingleTapUp(MotionEvent e) {
View childView=recyclerView.findChildViewUnder(e.getX(),e.getY());
if(childView!=null && listener!=null){
listener.onItemClick(childView,recyclerView.getChildAdapterPosition(childView));
}
return true;
}
#Override
public void onLongPress(MotionEvent e) {
View childView=recyclerView.findChildViewUnder(e.getX(),e.getY());
if(childView!=null && listener!=null){
listener.onItemLongClick(childView,recyclerView.getChildAdapterPosition(childView));
}
}
});
}
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent){
if (gestureDetectorCompat!=null){
boolean result=gestureDetectorCompat.onTouchEvent(motionEvent);
return result;
}else{
return false;
}
}
}
PhotoGalleryFragment.java
public class PhotoGalleryFragment extends Fragment implements RecyclerItemClickListener.OnRecyclerClickListener{
private RecyclerView recyclerView;
public ProgressBar progressBar;
public List<Photo> photos = new ArrayList<>();
public PhotoGalleryFragment() {
// Required empty public constructor
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_photo_gallery, container, false);
progressBar = (ProgressBar) view.findViewById(R.id.loading_indicator);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(),recyclerView,this));
progressBar.setVisibility(View.GONE);
setUpAdapter();
new FetchTask().execute();
return view;
}
private void setUpAdapter() {
//isAdded checks whether fragment has been added to the activity
if (isAdded()) {
recyclerView.setAdapter(new PhotoAdapter(photos));
}
}
#Override
public void onItemClick(View view, int position) {
Toast.makeText(getActivity(),"Item Clicked",Toast.LENGTH_LONG).show();
Intent intent=new Intent(getActivity(),DetailActivity.class);
//what should i pass in putExtra of intent
//intent.putExtra("IMAGE",photo.getLink());
startActivity(intent);
}
#Override
public void onItemLongClick(View view, int position) {
Toast.makeText(getActivity(),"Item Long Clicked",Toast.LENGTH_LONG).show();
}
private class PhotoHolder extends RecyclerView.ViewHolder {
private ImageView imageView;
private TextView textView;
public PhotoHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.imageview);
textView = (TextView) itemView.findViewById(R.id.textview);
}
public void bindItems(Photo photos1) {
Picasso.with(getActivity()).load(photos1.getImage()).into(imageView);
textView.setText(photos1.getTitle());
// Glide.with(getActivity()).load(photos1.getImage()).into(imageView);
}
}
private class PhotoAdapter extends RecyclerView.Adapter<PhotoHolder> {
private List<Photo> galleryItems;
public PhotoAdapter(List<Photo> galleryItems) {
this.galleryItems = galleryItems;
}
#Override
public PhotoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View view = layoutInflater.inflate(R.layout.list_item, parent, false);
return new PhotoHolder(view);
}
#Override
public void onBindViewHolder(PhotoHolder holder, int position) {
Photo photos2 = galleryItems.get(position);
holder.bindItems(photos2);
}
#Override
public int getItemCount() {
return galleryItems.size();
}
}
private class FetchTask extends AsyncTask<Void, Void, List<Photo>> {
#Override
protected void onPreExecute() {
super.onPreExecute();
if (photos.size() == 0) {
progressBar.setVisibility(View.VISIBLE);
}
}
#Override
protected List<Photo> doInBackground(Void... params) {
return new FlickrFetchr().fetchPhotos("android", "en-us", false);
}
#Override
protected void onPostExecute(List<Photo> photos1) {
super.onPostExecute(photos);
progressBar.setVisibility(View.GONE);
photos = photos1;
setUpAdapter();
}
}
}
DetailActivity.java
public class DetailActivity extends AppCompatActivity {
private ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
imageView=(ImageView)findViewById(R.id.detailimageview);
int img_id;
if (savedInstanceState != null ){
img_id = getIntent().getIntExtra("IMAGE",0);
imageView.setImageResource(img_id);
}
}
}
In onItemClick you can pass Like this
Toast.makeText(getActivity(),"Item Clicked",Toast.LENGTH_LONG).show();
Intent intent=new Intent(getActivity(),DetailActivity.class);
//what should i pass in putExtra of intent
intent.putExtra("IMAGE",photos.get(position).getLink());
startActivity(intent);
In DetailsActivity you can retrieve it by
if (getIntent().getStringExtra("IMAGE") != null) {
imageurl = getIntent().getStringExtra("IMAGE");
}

Unable to populate any Cards in RecyclerView, possible cause?

I am trying to populate CardView's inside a RecyclerView. Though I am able to log all the adapter values(to make sure they are non-empty) I can't populate any in the UI. Here is the Activity Code:
FoodActivity.class
public class FoodActivity extends AppCompatActivity
{
private RecyclerView foodView;
private List<Result> adapter_data;
private CustomPlacesAdapter adapter;
private LinearLayoutManager llm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food);
foodView = (RecyclerView)findViewById(R.id.foodRView);
adapter = new CustomPlacesAdapter(adapter_data);
adapter_data = new ArrayList<>();
llm = new LinearLayoutManager(this);
foodView.setLayoutManager(llm);
foodView.setAdapter(adapter);
doGetRequest("restaurants in los angeles airport");
}
private void doGetRequest(final String message)
{
ApiInterfacePlaces apiService =
ApiClientPlaces.getClient().create(ApiInterfacePlaces.class);
Call<PlacesPojo> call = apiService.getValues(message, Util.getKeyForPlaces());
call.enqueue(new Callback<PlacesPojo>()
{
#Override
public void onResponse(Call<PlacesPojo>call, Response<PlacesPojo> response)
{
try
{
Log.e("TAG",""+response.body().toString());
List<Result> response_res = response.body().getResults();
adapter_data = response_res;
adapter.notifyDataSetChanged();
}
catch (Exception e)
{
Toast.makeText(FoodActivity.this, "Check data connection", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<PlacesPojo> call, Throwable t) {
// Log error here since request failed
Log.e("FAILURE", t.toString());
}
});
}
}
Here is the code to the RecyclerView's adapter:
CustomPlacesAdapter.class
public class CustomPlacesAdapter extends RecyclerView.Adapter<CustomPlacesAdapter.HotelsViewHolder>
{
private DataHolder d2 = new DataHolder();
public class HotelsViewHolder extends RecyclerView.ViewHolder
{
private TextView hotelName;
private Typeface face;
private ImageView hotel_logo;
private Context mcontext;
HotelsViewHolder(View itemView)
{
super(itemView);
mcontext = itemView.getContext();
hotelName = (TextView)itemView.findViewById(R.id.hotelName);
face = Typeface.createFromAsset(itemView.getContext().getAssets(), "Fonts/Roboto-Regular.ttf");
hotelName.setTypeface(face);
hotel_logo = (ImageView)itemView.findViewById(R.id.logoOfHotel);
}
}
private static class DataHolder
{
List<Result> feeds;
}
public CustomPlacesAdapter(List<Result> feeds)
{
this.d2.feeds = feeds;
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public HotelsViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.food_item, viewGroup, false);
HotelsViewHolder pvh = new HotelsViewHolder(v);
return pvh;
}
#Override
public void onBindViewHolder(HotelsViewHolder feedViewHolder, int i)
{
feedViewHolder.hotelName.setText(d2.feeds.get(i).getName());
Picasso.with(feedViewHolder.mcontext).load(d2.feeds.get(i).getIcon()).into(feedViewHolder.hotel_logo);
}
#Override
public int getItemCount()
{
if(d2.feeds!=null)
{
return d2.feeds.size();
}
else
{
return 0;
}
}
}
This is the CardView that I use:
food_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
app:cardCornerRadius="5dp"
android:layout_height="100dp"
card_view:cardUseCompatPadding="false"
android:id="#+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logoOfHotel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/hotelName"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Cross checked many things, still unable to fix the issue, what is possibly causing this? Any help would be much appreciated.

my RecyclerView does not show anything

Help. I don't know why my RecyclerView does not show anything. My implementation of the adapter is right. I don't know where have I gone wrong.
Here's the Fragment class:
public class RemittanceFragment extends Fragment implements View.OnClickListener {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
#BindView(R.id.remit_cancel_view)
View remitCancelView;
#BindView(R.id.remit_checkpaid_view)
View remitCheckPaidView;
#BindView(R.id.remit_create_view)
View remitCreateView;
#BindView(R.id.remit_main_menu)
View remitMainMenuView;
#BindView(R.id.btn_cancel)
Button btnCancel;
#BindView(R.id.btn_checkpaid)
Button btnCheckPaid;
#BindView(R.id.btn_create)
Button btnCreate;
#BindView(R.id.btn_back)
TextView btnGoBack;
#BindView(R.id.btn_back2)
TextView btnGoBack2;
#BindView(R.id.remit_header_title)
TextView tvRemitHeaderTitle;
#BindView(R.id.remit_cancel_list)
RecyclerView cancelRecyclerView;
public RemittanceFragment() {
// Required empty public constructor
}
public static RemittanceFragment newInstance() {
RemittanceFragment fragment = new RemittanceFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_remit_menu, container, false);
ButterKnife.bind(this, view);
remitCancelView.setVisibility(View.GONE);
remitCheckPaidView.setVisibility(View.GONE);
remitCreateView.setVisibility(View.GONE);
btnCancel.setOnClickListener(this);
btnCreate.setOnClickListener(this);
btnCheckPaid.setOnClickListener(this);
btnGoBack.setOnClickListener(this);
btnGoBack2.setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
remitMainMenuView.setVisibility(View.GONE);
switch (v.getId()) {
case R.id.btn_cancel:
remitCancelView.setVisibility(View.VISIBLE);
tvRemitHeaderTitle.setText("CANCEL\nREMITTANCE");
populateData();
break;
case R.id.btn_checkpaid:
remitCheckPaidView.setVisibility(View.VISIBLE);
tvRemitHeaderTitle.setText("CHECK / PAID\nREMITTANCE");
break;
case R.id.btn_create:
remitCreateView.setVisibility(View.VISIBLE);
tvRemitHeaderTitle.setText("CREATE\nREMITTANCE");
break;
case R.id.btn_back:
case R.id.btn_back2:
remitMainMenuView.setVisibility(View.VISIBLE);
remitCancelView.setVisibility(View.GONE);
remitCheckPaidView.setVisibility(View.GONE);
remitCreateView.setVisibility(View.GONE);
tvRemitHeaderTitle.setText("REMITTANCE");
break;
default:
break;
}
}
public void populateData() {
List<RemitTransaction> transactions = new ArrayList<>();
transactions = RemitTransaction.createRemitTransactionList();
RemitTransactionListAdapter adapter = new RemitTransactionListAdapter
(transactions, getActivity());
cancelRecyclerView.setAdapter(adapter);
cancelRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
public static class RemitTransaction {
private String mRefno;
private String mDate;
private String mMsisdn;
private String mAmount;
public RemitTransaction(String refno, String date, String msisdn, String amount) {
mRefno = refno;
mDate = date;
mMsisdn = msisdn;
mAmount = amount;
}
public String getmRefno() {
return mRefno;
}
public String getmDate() {
return mDate;
}
public String getmMsisdn() {
return mMsisdn;
}
public String getmAmount() {
return mAmount;
}
public static ArrayList<RemitTransaction> createRemitTransactionList() {
ArrayList<RemitTransaction> transactions = new ArrayList<>();
for (int n = 0; n < 4; n++) {
transactions.add(n, new RemitTransaction(
"REF01253123" + n,
"July " + n + ", 2016",
"0920987654" + n,
"100" + n));
}
return transactions;
}
}
public class RemitTransactionListAdapter
extends RecyclerView.Adapter<RemitTransactionListAdapter.CancelVH>{
private List<RemitTransaction> mList;
private Context mContext;
public RemitTransactionListAdapter(List<RemitTransaction> list, Context context) {
mList = list;
mContext = context;
}
private Context getContext() {
return mContext;
}
#Override
public CancelVH onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = getContext();
View v = LayoutInflater.from(context).inflate(R.layout.remit_cancel_list_item, parent, false);
return new CancelVH(v);
}
#Override
public void onBindViewHolder(CancelVH holder, int position) {
RemitTransaction transaction = mList.get(position);
holder.cancelRefno.setText(transaction.getmRefno());
holder.cancelAmount.setText(transaction.getmAmount());
holder.cancelDate.setText(transaction.getmDate());
holder.cancelMsisdn.setText(transaction.getmMsisdn());
}
#Override
public int getItemCount() {
return mList.size();
}
public class CancelVH extends RecyclerView.ViewHolder {
#BindView(R.id.remit_item_refno) TextView cancelRefno;
#BindView(R.id.remit_item_amount) TextView cancelAmount;
#BindView(R.id.remit_item_date) TextView cancelDate;
#BindView(R.id.remit_item_msisdn) TextView cancelMsisdn;
public CancelVH(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
}
}
And here's the layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/utility_white"
android:paddingTop="#dimen/dimen_margin_vertical_extra_large">
<android.support.v7.widget.RecyclerView
android:id="#+id/remit_cancel_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
And here's the list_item layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/remit_item_refno"
style="#style/RemitListItem"
android:text="VW832191"
android:textStyle="bold"
android:layout_alignParentStart="true"/>
<TextView
android:id="#+id/remit_item_amount"
style="#style/RemitListItem"
android:text="100.00"
android:textStyle="bold"
android:layout_alignParentEnd="true"/>
<TextView
android:id="#+id/remit_item_date"
style="#style/RemitListItem"
android:text="2016-07-20"
android:layout_alignParentStart="true"
android:layout_below="#+id/remit_item_refno"/>
<TextView
android:id="#+id/remit_item_msisdn"
style="#style/RemitListItem"
android:text="09273450686"
android:layout_alignParentEnd="true"
android:layout_below="#+id/remit_item_amount"/>
</RelativeLayout>
Hope you can all help me. Thank you!
in previous versions of support library 23.2.0 wrap_content not work for RecyclerView ,and with support library 23.2.0 and above wrap_content work perfectly (now latest version is 24.0.0),
i guess that is your problem.

Categories

Resources