RecyclerView in fragments not working properly - java

I want to make a RecyclerView containing Cards inside it.
The problem is that I'm getting something weird. Like shown in screenshot below (Notice the another card overlapping the card below - the card below is only what I want to be displayed):
Here's ListContentAAR.java file's code:
class ListContentAAR {
int hImage;
String hPicTag;
String hDescription;
String hLocation;
Button btn_accept;
Button btn_share;
String postDate;
String postTime;
String postedBy;
ListContentAAR(int hImage,
String hPicTag,
String hDescription,
String hLocation,
Button btn_accept,
Button btn_share,
String postDate,
String postTime,
String postedBy) {
this.hImage = hImage;
this.hPicTag = hPicTag;
this.hDescription = hDescription;
this.hLocation = hLocation;
this.btn_accept = btn_accept;
this.btn_share = btn_share;
this.postDate = postDate;
this.postTime = postTime;
this.postedBy = postedBy;
}
}
Here's RVAdapterAAR.java file's code:
public class RVAdapterAAR extends RecyclerView.Adapter<RVAdapterAAR.PersonViewHolder> {
public static class PersonViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
ImageView hImage;
TextView hPicTag;
TextView hDescription;
TextView hLocation;
Button btn_accept;
Button btn_share;
TextView postDate;
TextView postTime;
TextView postedBy;
PersonViewHolder(View itemView) {
super(itemView);
cardView = (CardView) itemView.findViewById(R.id.card_accept_request);
hImage = (ImageView) itemView.findViewById(R.id.h_pic_accept);
hPicTag = (TextView) itemView.findViewById(R.id.h_pic_tag);
hDescription = (TextView) itemView.findViewById(R.id.h_description_accept);
hLocation = (TextView) itemView.findViewById(R.id.h_location_tag);
btn_accept = (Button) itemView.findViewById(R.id.btn_accept);
btn_share = (Button) itemView.findViewById(R.id.btn_share);
postDate = (TextView) itemView.findViewById(R.id.post_date);
postTime = (TextView) itemView.findViewById(R.id.post_time);
postedBy = (TextView) itemView.findViewById(R.id.posted_by);
}
}
List<ListContentAAR> listContentAARs;
RVAdapterAAR(List<ListContentAAR> listContentAARs) {
this.listContentAARs = listContentAARs;
}
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_accept_a_request, viewGroup, false);
PersonViewHolder personViewHolder = new PersonViewHolder(view);
return personViewHolder;
}
public void onBindViewHolder (PersonViewHolder personViewHolder, int i) {
personViewHolder.hImage.setImageResource(listContentAARs.get(i).hImage);
personViewHolder.hPicTag.setText(listContentAARs.get(i).hPicTag);
personViewHolder.hDescription.setText(listContentAARs.get(i).hDescription);
personViewHolder.hLocation.setText(listContentAARs.get(i).hLocation);
// something for btn_accept
// something for btn_share
personViewHolder.postDate.setText(listContentAARs.get(i).postDate);
personViewHolder.postTime.setText(listContentAARs.get(i).postTime);
personViewHolder.postedBy.setText(listContentAARs.get(i).postedBy);
}
public int getItemCount() {
return listContentAARs.size();
}
}
Here's AcceptARequest.java file's code:
public class AcceptARequest extends Fragment{
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public List<ListContentAAR> listContentAARs;
public RecyclerView recyclerView;
public AcceptARequest() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment AcceptARequest.
*/
// TODO: Rename and change types and number of parameters
public static AcceptARequest newInstance(String param1, String param2) {
AcceptARequest fragment = new AcceptARequest();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_accept_a_request, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.accept_request_list);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setHasFixedSize(true);
initializeData();
initializeAdapter();
return rootView;
}
private void initializeData(){
listContentAARs = new ArrayList<>();
listContentAARs.add(new ListContentAAR(R.drawable.ic_action_facebook,
"H pic goes here",
"H description goes here",
"H location goes here",
R.id.btn_accept,
R.id.btn_share,
"date",
"time",
"posted by"));
}
private void initializeAdapter(){
RVAdapterAAR adapter = new RVAdapterAAR(listContentAARs);
recyclerView.setAdapter(adapter);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
Here's fragment_accept_a_request.xml file's code:
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.abc.xyz.AcceptARequest">
<include layout="#layout/accept_a_request_recyclerview"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/accept_request_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
Here's accept_a_request_recyclerview.xml file's code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="#layout/fragment_accept_a_request">
<android.support.v7.widget.CardView
android:id="#+id/card_accept_request"
android:layout_width="match_parent"
android:layout_height="#dimen/card_accept_request"
app:cardElevation="2dp"
app:cardUseCompatPadding="true"
app:contentPadding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/h_pic_accept"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:layout_gravity="center_horizontal|center_vertical"/>
<TextView
android:id="#+id/h_pic_tag"
android:layout_width="match_parent"
android:layout_height="#dimen/homeless_pic_dimen_accept"
android:text="h pic goes here"
android:gravity="center_horizontal|center_vertical"/>
<TextView
android:id="#+id/h_description_accept"
android:layout_below="#+id/h_pic_tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:text="h description goes here"
android:maxLines="5"/>
<TextView
android:id="#+id/h_location_tag"
android:layout_below="#id/h_description_accept"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:text="h location goes here"
android:gravity="center_horizontal|center_vertical"
android:paddingTop="#dimen/paddings"
android:paddingBottom="#dimen/paddings"/>
<LinearLayout
android:id="#+id/btn_accept_share_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/h_location_tag">
<Button
android:id="#+id/btn_accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_accept"
android:textColor="#color/colorPrimary"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="#+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_share"
android:textColor="#color/colorPrimary"
style="?android:attr/borderlessButtonStyle"/>
</LinearLayout>
<LinearLayout
android:id="#+id/date_time_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/btn_accept_share_container"
android:layout_alignRight="#+id/btn_accept_share_container"
android:orientation="vertical"
android:layout_below="#id/homeless_location_tag">
<TextView
android:id="#+id/post_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"/>
<TextView
android:id="#+id/post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="time"/>
</LinearLayout>
<TextView
android:id="#+id/posted_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="posted by [name]"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
As I'm a beginner, I totally have no idea about what is going wrong here!

The mistake is that in onCreateViewHolder you should only inflate the content of recyclerView item, but not the very RecyclerView.The right implementation is as follow:
recyclerview_item.xml
<android.support.v7.widget.CardView
android:id="#+id/card_accept_request"
android:layout_width="match_parent"
android:layout_height="#dimen/card_accept_request"
app:cardElevation="2dp"
app:cardUseCompatPadding="true"
app:contentPadding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/h_pic_accept"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:layout_gravity="center_horizontal|center_vertical"/>
<TextView
android:id="#+id/h_pic_tag"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:text="H pic goes here"
android:gravity="center_horizontal|center_vertical"/>
<TextView
android:id="#+id/h_description_accept"
android:layout_below="#+id/h_pic_tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:text="H description goes here"
android:maxLines="5"/>
<TextView
android:id="#+id/h_location_tag"
android:layout_below="#id/h_description_accept"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:text="H location goes here"
android:gravity="center_horizontal|center_vertical"
android:paddingTop="#dimen/paddings"
android:paddingBottom="#dimen/paddings"/>
<LinearLayout
android:id="#+id/btn_accept_share_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/homeless_location_tag">
<Button
android:id="#+id/btn_accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_accept"
android:textColor="#color/colorPrimary"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="#+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_share"
android:textColor="#color/colorPrimary"
style="?android:attr/borderlessButtonStyle"/>
</LinearLayout>
<LinearLayout
android:id="#+id/date_time_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/btn_accept_share_container"
android:layout_alignRight="#+id/btn_accept_share_container"
android:orientation="vertical"
android:layout_below="#id/homeless_location_tag">
<TextView
android:id="#+id/post_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"/>
<TextView
android:id="#+id/post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="time"/>
</LinearLayout>
<TextView
android:id="#+id/posted_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="posted by [name]"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
your_fragment_layout.xml
<android.support.v7.widget.RecyclerView
android:id="#+id/accept_request_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
In your Activity you inflate Fragment from your_fragment_layout.xml
and then in onCreateViewHolder you should replace this line:
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_accept_a_request, viewGroup, false);
on this line :
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recyclerview_item, viewGroup, false);

After messing up a lot with this problem, I finally figured out the solution.
It was simple.
I just changed the RelativeLayout to LinearLayout, and it worked like a charm!
Here's the final fragment_accept_a_request.xml file's code:
<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="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.humanehelper.humanehelper.AcceptARequest">
<android.support.v7.widget.RecyclerView
android:id="#+id/accept_request_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<include layout="#layout/accept_a_request_recyclerview"/>
</LinearLayout>
and here's accept_a_request_recyclerview.xml file's code:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="#layout/fragment_accept_a_request">
<android.support.v7.widget.CardView
android:id="#+id/card_accept_request"
android:layout_width="match_parent"
android:layout_height="#dimen/card_accept_request"
app:cardElevation="2dp"
app:cardUseCompatPadding="true"
app:contentPadding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/h_pic_accept"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:layout_gravity="center_horizontal|center_vertical"/>
<TextView
android:id="#+id/h_pic_tag"
android:layout_width="match_parent"
android:layout_height="#dimen/homeless_pic_dimen_accept"
android:text="h pic goes here"
android:gravity="center_horizontal|center_vertical"/>
<TextView
android:id="#+id/h_description_accept"
android:layout_below="#+id/h_pic_tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:text="h description goes here"
android:maxLines="5"/>
<TextView
android:id="#+id/h_location_tag"
android:layout_below="#id/h_description_accept"
android:layout_width="match_parent"
android:layout_height="#dimen/h_pic_dimen_accept"
android:text="h location goes here"
android:gravity="center_horizontal|center_vertical"
android:paddingTop="#dimen/paddings"
android:paddingBottom="#dimen/paddings"/>
<LinearLayout
android:id="#+id/btn_accept_share_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/h_location_tag">
<Button
android:id="#+id/btn_accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_accept"
android:textColor="#color/colorPrimary"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="#+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_share"
android:textColor="#color/colorPrimary"
style="?android:attr/borderlessButtonStyle"/>
</LinearLayout>
<LinearLayout
android:id="#+id/date_time_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/btn_accept_share_container"
android:layout_alignRight="#+id/btn_accept_share_container"
android:orientation="vertical"
android:layout_below="#id/homeless_location_tag">
<TextView
android:id="#+id/post_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"/>
<TextView
android:id="#+id/post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="time"/>
</LinearLayout>
<TextView
android:id="#+id/posted_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="posted by [name]"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

Related

OnItemClick isn't working on a ListView item

I have a custom layout for the list's cells where you have a checkbox and 3 text elements. I found on Stackoverflow that I should add android:descendantFocusability = "blocksDescendants" on my LinearLayout where the list is but it doesn't change anything.
Here is my XML for the page with the list :
<?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:id="#+id/cl_fragment_detail_apero"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
tools:context=".ui.home.AperoDetailFragment"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/name_apero"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingHorizontal="10dp"
android:gravity="left"
android:textSize="18sp" />
<TextView
android:id="#+id/date_apero"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingHorizontal="10dp"
android:ems="10"
android:gravity="right"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#DDDDDD" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/txtView_shopping_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingHorizontal="10dp"
android:text="#string/shopping_list_title" />
<Button
android:id="#+id/btn_add_ingredients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorAccent"
android:clickable="true"
android:focusable="true"
android:padding="15dp"
android:src="#android:drawable/ic_menu_add"
android:text="#string/btn_add_ingredient"
android:textColor="#FFFFFF" />
</LinearLayout>
<ListView
android:id="#+id/list_ingredient"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal" />
</LinearLayout>
then in my Java code I set the listener like this :
#Override
public View onCreateView(#NonNull final LayoutInflater inflater,
final ViewGroup container, Bundle savedInstanceState) {
root = inflater.inflate(R.layout.fragment_detail_apero, container, false);
final TextView name = (TextView) root.findViewById(R.id.name_apero);
name.setText(detailApero.name);
TextView date = (TextView) root.findViewById(R.id.date_apero);
date.setText(detailApero.date);
// some code that aren't useful right now
//-------------- List of ingredients for the detailed apero
final ListView list_ingredient = (ListView) root.findViewById(R.id.list_ingredient);
LaperoDatabase db = Room.databaseBuilder(root.getContext(),
LaperoDatabase.class, "lapero_db").allowMainThreadQueries().build();
IngredientDao dbIngredient = db.getIngredientDao();
//#TODO control if we get the right ingredients
ArrayList<Ingredient> ingredient_of_this_apero = (ArrayList<Ingredient>) dbIngredient.getIngredientsFromApero(detailApero.aid);
IngredientAdapter adapter = new IngredientAdapter(root.getContext(), R.layout.ingredient_cell_layout, ingredient_of_this_apero);
list_ingredient.setAdapter(adapter);
list_ingredient.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
Ingredient selected_ingredient = (Ingredient) adapter.getItemAtPosition(position);
Log.e("test","okasodkdaso");
}
});
return root;
}
I also tried using a OnItemLongClickListener but it also does nothing. How can I put a listener for the list items ?

my app in android studio is crashing when i come to the part recyclerView.setAdapter(adapter);

I am trying to fetch some data in android studio from my online database backendless.com but the proplem is not with the online serves it is when i try to inflate the data. i dont know is it in the layaot file or in the java class
this is my java activitiy ViewMyBusiness.java
public class ViewMyBusiness extends AppCompatActivity {
ListView recyclerView;
private View mProgressView;
private View mLoginFormView;
private TextView tvLoad;
ContactsAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_my_business);
recyclerView = findViewById(R.id.recycler_view);
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
tvLoad = findViewById(R.id.tvLoad);
String whereClause = "userEmail = '" + BackendlessCall.user.getEmail() + "'";
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);
queryBuilder.setGroupBy("companyName");
showProgress(true);
Backendless.Persistence.of(Contact.class).find(queryBuilder, new AsyncCallback<List<Contact>>() {
#Override
public void handleResponse(List<Contact> response) {
adapter = new ContactsAdapter(ViewMyBusiness.this, response);
//the crash is here
recyclerView.setAdapter(adapter);
showProgress(false);
}
#Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(ViewMyBusiness.this, "ERROR: " + fault.getMessage(), Toast.LENGTH_SHORT).show();
showProgress(false);
}
});
}
this is the contacts adapter java class
public class ContactsAdapter extends ArrayAdapter<Contact> {
private Context context;
private List<Contact> contacts;
public ContactsAdapter(Context context, List<Contact> list)
{
super(context, R.layout.row_layout, list);
this.context = context;
this.contacts = list;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_layout, parent, false);
TextView tvChar = convertView.findViewById(R.id.tvChar);
TextView tvCName = convertView.findViewById(R.id.tvCName);
TextView tvBField = convertView.findViewById(R.id.tvBField);
tvChar.setText(contacts.get(position).getCompanyName().toUpperCase().charAt(0) + "");
tvCName.setText(contacts.get(position).getCompanyName());
tvBField.setText(contacts.get(position).getBusinessField());
return convertView;
}
}
the layout for the listview in activity_view_my_business.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"
android:orientation="vertical"
tools:context=".ViewMyBusiness">
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="200dp"
android:visibility="gone" />
<TextView
android:id="#+id/tvLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:clickable="true"
android:focusable="true"
android:gravity="center_horizontal"
android:text="Loading...please wait..."
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/login_form"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Business"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/row_layout"/>
</LinearLayout>
</LinearLayout>
this is the view file that will inflate when data is passed
the row_layout.xml
<?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"
android:layout_margin="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/List"
android:orientation="horizontal">
<TextView
android:id="#+id/tvChar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="A"
android:textColor="#color/ListText"
android:textSize="48sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"
android:orientation="vertical">
<TextView
android:id="#+id/tvCName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text="TextView"
android:textColor="#color/ListText"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvBField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="TextView"
android:textColor="#color/ListText" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You are getting NullPointerException in that line, becasue in this line -
recyclerView = findViewById(R.id.recycler_view);
you are assigning null value to recyclerView variable !
It's because in the activity layout file you have defined a list view not RecyclerView, change this part
<ListView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/row_layout"/>
to this part of xml code -->
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/row_layout"/>
and to use recyclerView you have to add these -->
implementation 'com.android.support:recyclerview-v7:28.0.0' ,
dependency to your build.gradle (app:module) file
and here is official documentation about RecyclerView - Andorid RecyclerView
Enjoy!!

Dynamic TextView not updating in fragment

I'm trying to set a TextView that's in a fragment but the text won't update in the view. The text is 1 of 2 pages in a ViewPager. The ViewPager is inside another fragment that has a button which when clicked uses an interface to the MainActivity that calls the changeText() that's inside the fragment with my text.
Fragment Inside ViewPager:
public class PlaceholderFragment extends Fragment {
public TextView textFV;
public PlaceholderFragment() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_pull, container, false);
textFV = rootView.findViewById(R.id.textFV);
return rootView;
}
#Override
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void changeText() {
textFV.setText("Test"); - Won't update view.
System.out.println(textFV.getText()); - Shows correct text.
}
}
Relevant part of Fragment that contains ViewPager:
OnHeadlineSelectedListener callback;
public void setOnHeadlineSelectedListener(OnHeadlineSelectedListener callback) {
this.callback = callback;
}
public interface OnHeadlineSelectedListener {
void onArticleSelected();
}
//...
#Override
public void onClick (View v) {
callback.onArticleSelected();
}
Relevant MainActivity Part:
public void onArticleSelected() {
PlaceholderFragment articleFrag = (PlaceholderFragment) getSupportFragmentManager().findFragmentById(R.id.viewpager);
if (articleFrag != null) {
articleFrag.changeText();
}
}
Here is the layout that contains the TextView:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:id="#+id/tab_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:id="#+id/containerPull"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/textsLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/label_left_margin"
android:layout_marginTop="5dp"
android:text="#string/label_common"
android:textColor="#color/colorLabelText"
android:textSize="18sp" />
<TextView
android:id="#+id/textFV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
Here's where the button and ViewPager is. The button is the ImageButton:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white">
<android.support.v7.widget.Toolbar
android:id="#+id/pullToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="Information"
app:titleTextAppearance="#style/TextAppearance.Widget.AppCompat.Toolbar.Title.Montserrat">
<ImageButton
android:id="#+id/toolbarButtonPull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="1dp"
android:background="#drawable/button_toolbar_default"
android:contentDescription="Pull"
android:padding="15dp"
android:src="#drawable/ic_arrow_downward_black_24dp" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabTextAppearance="#style/TextAppearance.Design.Tab.NoCaps">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab1" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab2" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" />
</android.support.design.widget.CoordinatorLayout>
Looks like your textFV is inside layout that has visibility gone. Can it be the problem?
<LinearLayout
android:id="#+id/containerPull"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
**android:visibility="gone">**
<TextView
android:id="#+id/textsLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/label_left_margin"
android:layout_marginTop="5dp"
android:text="#string/label_common"
android:textColor="#color/colorLabelText"
android:textSize="18sp" />
<TextView
android:id="#+id/textFV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textColor="#android:color/black"
android:textSize="18sp" />

Android CustomListAdapter Setting TextView from EditText OnClick in TAB

On one of my tabs I have a Listview that I want to populate when a user enters text on the edittext and then presses a button. The edittext and the button are on the tabbed layout along with the listview.
The textview and imageview are set in the customlistadapter. But when I press the button nothing happens and I can't seem to work out why.
Tab3.java
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.tab3, container, false);
final EditText notes = (EditText) v.findViewById(R.id.editText);
listView=(ListView)v.findViewById(R.id.list);
Button button = (Button) v.findViewById(R.id.button3);
String note = notes.getText().toString();
int[] cross = new int[]{R.drawable.cross};
String [] notesofrules = new String[]{note};
final CustomListAdapter adapter=new CustomListAdapter(this.getActivity(), notesofrules, cross);
listView=(ListView) v.findViewById(R.id.list);
Button rulesSet = (Button)v.findViewById(R.id.button3);
rulesSet.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
listView.setAdapter(adapter);
}
});
return v;
}
CustomListAdaper:
public CustomListAdapter(Activity context, String[] notes, int[] imageCross) {
super(context, R.layout.item);
// TODO Auto-generated constructor stub
this.context=context;
this.notes = notes;
this.imageCross = imageCross;
}
public View getView(final int position, View view, ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.item, null,false);
TextView ruleNotesSet = (TextView) rowView.findViewById(R.id.textView1);
ImageView image = (ImageView) rowView.findViewById(R.id.icon);
image.setImageResource(imageCross[position]);
ruleNotesSet.setText(notes[position]);
return rowView;
}
tab3.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
>
<TextView android:text="#string/thirdTabTitle" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF9900"
android:id="#+id/textView"
android:textIsSelectable="true"
android:textSize="55px"
android:shadowColor="#73ffffff"
android:fontFamily="sans-serif-bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="100px"
android:ems="10"
android:padding="10dp"
android:id="#+id/editText"
android:background="#drawable/edittext_rounded_corners"
android:layout_marginTop="18dp"
android:layout_below="#+id/textView"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="#string/addnote"
android:background="#drawable/calculate_button"
android:textColor="#000000"
android:fontFamily="sans-serif-bold"
android:layout_below="#+id/editText"
android:textSize="40px"/>
<TextView
android:id="#+id/notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textSize="45px"
android:layout_below="#+id/button3"
android:fontFamily="sans-serif-bold"
android:layout_toRightOf="#id/autohighlight_checkbox"
/>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/notes" />
</RelativeLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4CBE99"
android:textSize="14dp"
android:text="Item"
android:textAllCaps="true"
android:textStyle="bold" />
<ImageView
android:id="#+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp" />
</LinearLayout>
</LinearLayout>
I think your adapter is empty. You only need to set it once, then make a refresh function in your adapter you'll call in your activity's onClick
public void refresh(String[] notes, int[] imageCross) {
this.notes = notes;
this.imageCross = imageCross;
this.notifySataSetChanged();
}

Android List View shows items, but text is empty

I am experiencing a very weird issue where I am unable to view any text/data, but it clearly shows the number of items in the list.
I have confirmed that dataList has data, and I am able to get the exact same string that I set after debugging.
Parent Fragment:
ListView InboxListView = (ListView) view.findViewById(R.id.listViewInbox);
InboxAdapter adapter = new InboxAdapter(mActivity, R.layout.activity_inbox_item, dataList, NotificationInbox.this);
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SwipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:padding="15dp"
android:id="#+id/searchBarInbox"
android:hint="Search"
android:layout_height="wrap_content" />
<ListView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="49dp"
android:id="#+id/listViewInbox" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Adapter: http://pastebin.com/mSUrdLcW << CLICK
public class InboxAdapter extends ArrayAdapter<InboxBO> {
NotificationInbox fragment;
Context context;
List<InboxBO> inboxForSharedPref;
List<InboxBO> inboxList;
int layoutResID;
SharedPreferences prefs;
private ArrayList<InboxBO> inboxarraylist;
private SparseBooleanArray mSelectedItemIds;
public InboxAdapter(Context context, int layoutResourceID, List<InboxBO> objs, NotificationInbox fragment) {
super(context, layoutResourceID, objs);
mSelectedItemIds = new SparseBooleanArray();
this.context = context;
this.inboxList = objs;
this.layoutResID = layoutResourceID;
this.inboxarraylist = new ArrayList<InboxBO>();
this.inboxarraylist.addAll(inboxList);
this.fragment = fragment;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
inboxHolder inboxholder;
View view = convertView;
if (view == null) {
view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(layoutResID, parent, false);
//LayoutInflater inflater = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
//LayoutInflater inflater = LayoutInflater.from(getContext());
//inflater.inflate(R.layout.activity_inbox_item, null);
inboxholder = new inboxHolder();
//view = inflater.inflate(layoutResID, parent, false);
prefs = context.getSharedPreferences(
Constants.PREF_NAME, 0);
inboxholder.swipeLayout = (SwipeLayout)view.findViewById(R.id.swipe_layout);
inboxholder.senderNameText = (TextView) view.findViewById(R.id.senderNameText);
inboxholder.pushDateText = (TextView) view.findViewById(R.id.pushDateText);
inboxholder.pushTimeText = (TextView) view.findViewById(R.id.pushTimeText);
inboxholder.messageText = (TextView) view.findViewById(R.id.messageText);
inboxholder.delete = (TextView)view.findViewById(R.id.delete);
inboxholder.itemLayout = (RelativeLayout) view.findViewById(R.id.relativeViewInbox);
inboxholder.swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
inboxholder.delete.setOnClickListener(onDeleteListener(position, inboxholder));
view.setTag(inboxholder);
}
else {
inboxholder = (inboxHolder) view.getTag();
}
InboxBO mItem = inboxList.get(position);
if(mItem!=null){
inboxholder.senderNameText.setText((String)mItem.getTitle());
inboxholder.pushDateText.setText(new Date().toString());
inboxholder.pushTimeText.setText(new Date().toString());
inboxholder.messageText.setText((String)mItem.getMessage());
}
return view;
}
// For swipe action
private View.OnClickListener onDeleteListener(final int position, final inboxHolder holder) {
return new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
context);
alert.setTitle("Delete Message");
alert.setMessage("Are you sure you wish to delete this message?");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
inboxList.remove(position);
Gson gson = new Gson();
inboxForSharedPref = fragment.getStoredMessages();
inboxForSharedPref = inboxList;
String jsonSavePref = gson.toJson(inboxForSharedPref);
fragment.commitToStoredList(jsonSavePref);
Toast.makeText(context, "Message Deleted!",
Toast.LENGTH_SHORT).show();
holder.swipeLayout.close();
fragment.retrieveMessage();
dialog.dismiss();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
};
}
// Algorithm to filter out listview based on text changed in listview searchbox
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
inboxList.clear();
if (charText.length() == 0) {
inboxList.addAll(inboxarraylist);
}
else
{
for (InboxBO ilist : inboxarraylist)
{
/*if (ilist.getDate().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getMessage().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getSendername().toLowerCase(Locale.getDefault()).contains(charText))
{
inboxList.add(ilist);
}*/
if(ilist.getTitle().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getMessage().toLowerCase(Locale.getDefault()).contains(charText) ){
inboxList.add(ilist);
}
}
}
notifyDataSetChanged();
}
public static class inboxHolder {
TextView senderNameText, pushDateText, pushTimeText, messageText, delete, title;
RelativeLayout itemLayout;
private SwipeLayout swipeLayout;
}
// Methods below are for multi-deletion
public void toggleSelection(int position) {
selectView(position, !mSelectedItemIds.get(position));
}
// Remove selection after unchecked
public void remove(InboxBO object) {
inboxList.remove(object);
Gson gson = new Gson();
inboxForSharedPref = fragment.getStoredMessages();
inboxForSharedPref = inboxList;
String jsonSavePref = gson.toJson(inboxForSharedPref);
fragment.commitToStoredList(jsonSavePref);
notifyDataSetChanged();
}
// Item checked on selection
public void selectView(int position, boolean value) {
if (value)
mSelectedItemIds.put(position, value);
else
mSelectedItemIds.delete(position);
notifyDataSetChanged();
}
// Get number of selected item
public int getSelectedCount() {
return mSelectedItemIds.size();
}
public SparseBooleanArray getSelectedIds() {
return mSelectedItemIds;
}
public void removeSelection() {
mSelectedItemIds = new SparseBooleanArray();
notifyDataSetChanged();
}
}
Adapter XML:
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/bottom_wrapper"
android:layout_width="100dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<TextView
android:id="#+id/delete"
android:text="Delete"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/relativeViewInbox"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:text="SenderName"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/senderNameText"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:text="PushDate"
android:gravity="right"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/pushDateText" />
</LinearLayout>
<TextView
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="Message..."
android:id="#+id/messageText"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout" />
<TextView
android:layout_width="match_parent"
android:text="PushTime"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/black"
android:layout_height="match_parent"
android:id="#+id/pushTimeText"
android:layout_alignTop="#+id/messageText" />
</RelativeLayout>
</com.daimajia.swipe.SwipeLayout>
EDIT: Screenshot added
EDIT2: Clarified parent fragment calling the adapter.
EDIT3: I did a temporary fix. Apparently the RelativeLayout and the Linear Layout in the AdapterXML were the cause of my misery. I'm not exactly sure why, though. I think it's the RelativeLayout and the LinearLayout somehow not displaying the text. Removing those two tags will display the texts in a linear fashion.
Try this
Adapter XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_wrapper"
android:layout_width="100dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<TextView
android:id="#+id/delete"
android:text="Delete"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/relativeViewInbox"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:text="SenderName"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/senderNameText"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:text="PushDate"
android:gravity="right"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/pushDateText" />
</LinearLayout>
<TextView
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="Message..."
android:id="#+id/messageText"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout" />
<TextView
android:layout_width="match_parent"
android:text="PushTime"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/black"
android:layout_height="match_parent"
android:id="#+id/pushTimeText"
android:layout_alignTop="#+id/messageText" />
</RelativeLayout>

Categories

Resources