0

Before asking this question, I reviewed as carefully as I could the following:

Android - RecyclerView Data not showing up

RecyclerView is not showing any item

Recycler View Not Showing Anything

android recyclerview doesn't display items

I tried to follow the suggestions in the above as best as I could. However, I still have no items displayed in the RecyclerView in my application.

Below, you will find my code. Please note:

1) I included only what I thought are the relevant portions of my code

2) I am using GreenRobot EventBus to update the adapter. That's what the onEvent method comes in.

3) When running the application, all the log statements (before/after an operation) in the code below are produced. I reviewed the logcat. I could not find any related warnings/errors.

At this point, I am at a loss. I feel as if I am missing something pretty obvious/basic. I just do not know what. UI is not my specialty. I would appreciate any suggestions for resolving this problem.

Thanks,

CODE

public class MainActivity extends FragmentActivity
{

private UserLocationInformationAdapter mUserLocationInformationAdapter;
private RecyclerView recyclerView;

private ArrayList<Classes.UserLocationInformation> _mWifidetails;


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    recyclerView = (RecyclerView) findViewById(R.id.wifiData);


    init();


}

private void init()
{

    _mWifidetails = new ArrayList<Classes.UserLocationInformation>();

    Log.i(TAG, " - init - _mWifidetails.size() - "+_mWifidetails.size());

    mUserLocationInformationAdapter = new UserLocationInformationAdapter(MainActivity.this, _mWifidetails);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mUserLocationInformationAdapter);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(MainActivity.this);
    recyclerView.setLayoutManager(mLayoutManager);
    mUserLocationInformationAdapter.notifyDataSetChanged();

    Log.i(TAG, " - init - Recycler view set up --- ");

}

@Subscribe
public void onEvent(MessageEvent event)
{

    wifi_data = new ArrayList<>();

    Log.i(TAG, " - onEvent - Event posted. Taking action --- ");

    _mWifidetails = event.getMwifiModal();

    Log.i(TAG, " - onEvent - _mWifidetails.size() - "+_mWifidetails.size());

    mUserLocationInformationAdapter.notifyDataSetChanged();

    Log.i(TAG, " - onEvent - Event posted. Action completed --- ");

}

public static class UserLocationInformationAdapter extends RecyclerView.Adapter<UserLocationInformationAdapter.ViewHolder>
{
    private ArrayList<UserLocationInformation> mDataset;
    private LayoutInflater mInflater;
    private WifiDetails.ItemClickListener mClickListener;

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
    {

        public TextView ssidTV , wifiLevelTV, disTextView;


        ViewHolder(View textView)
        {
            super(textView);
            ssidTV = (TextView) textView.findViewById(R.id.ssidTV);
            wifiLevelTV = (TextView) textView.findViewById(R.id.wifi_level);
            disTextView = (TextView) textView.findViewById(R.id.distanceTv);

        }

        @Override
        public void onClick(View view)
        {
            if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
        }

    }

     public UserLocationInformationAdapter(Context context, ArrayList<UserLocationInformation> myDataset)
    {
        this.mInflater = LayoutInflater.from(context);
        mDataset = myDataset;
    }

    @Override
    public UserLocationInformationAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                                          int viewType)
    {
         TextView v = (TextView) mInflater
                .inflate(R.layout.wifi_detail_adapter, parent, false);

        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {

        String address = "Address: " + mDataset.get(position).address;
        String latitude = "Latitude: " + mDataset.get(position).lat;
        String longitude = "Longitude: " + mDataset.get(position).lon;

       //SHOULD THE ABOVE THREE LINES BE REPLACED BY THESE THREE?
            //String address = "Address: " + mDataset.get(mDataset.size() - 1).address;
            //String latitude = "Latitude: " + mDataset.get(mDataset.size() - 1).lat;
            //String longitude = "Longitude: " + mDataset.get(mDataset.size() - 1).lon;

        holder.ssidTV.setText(address);
        holder.wifiLevelTV.setText(latitude);
        holder.disTextView.setText(longitude);

        holder.ssidTV.setVisibility(View.VISIBLE);
        holder.wifiLevelTV.setVisibility(View.VISIBLE);
        holder.disTextView.setVisibility(View.VISIBLE);

    }

    @Override
    public int getItemCount()
    {
        return mDataset.size();
    }

}

}

LAYOUTS

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/wifiData"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="2dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:clickable="true"
            android:splitMotionEvents="false"
            android:text="User Location Information" />

</LinearLayout>

wifi_detail_adapter.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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.CardView
    android:id="@+id/view2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:clickable="true"
    android:elevation="12dp"
    app:cardCornerRadius="10dp"
    android:layout_margin="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_margin="10dp">


    <TextView
        android:id="@+id/ssidTV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Address:: "/>

    <TextView
        android:id="@+id/wifi_level"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Latitude:: "/>

    <TextView
        android:id="@+id/distanceTv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Longitude:: "/>

    </LinearLayout>
</android.support.v7.widget.CardView>

</LinearLayout>
Alireza Bideli
  • 834
  • 2
  • 9
  • 31

1 Answers1

0

You are passing an empty list to the adapter

_mWifidetails = new ArrayList<Classes.UserLocationInformation>();

mUserLocationInformationAdapter = new UserLocationInformationAdapter(MainActivity.this, _mWifidetails);

_mWifidetails are empty

Mohammed Alaa
  • 3,140
  • 2
  • 19
  • 21