Java Andoid适配器无法用视图填充活动

Java Andoid适配器无法用视图填充活动,java,android,android-layout,android-recyclerview,Java,Android,Android Layout,Android Recyclerview,在我的MainActivity中,我使用RecyclerView用图像和名称填充活动,但当我运行应用程序时,活动为空。称为适配器,其中填充了包含“id”的数据对象和数组。适配器会将item_视图充气,并使用一个ViewHolder来保存textview并充当onClickListener 关于为什么它仍然是空的以及我如何填充它,有什么想法吗 主要活动: package com.com.com; import androidx.appcompat.app.AppCompatActivity; i

在我的MainActivity中,我使用RecyclerView用图像和名称填充活动,但当我运行应用程序时,活动为空。称为适配器,其中填充了包含“id”的数据对象和数组。适配器会将item_视图充气,并使用一个ViewHolder来保存textview并充当onClickListener

关于为什么它仍然是空的以及我如何填充它,有什么想法吗

主要活动:

package com.com.com;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private RecyclerView.Adapter mDataAdapter;
    private RecyclerView.LayoutManager mDataLayoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mRecyclerView = (RecyclerView)  findViewById(R.id.recyclerView);
        mRecyclerView.setNestedScrollingEnabled(false);
        mRecyclerView.setHasFixedSize(true);
        mMatchesLayoutManager = new LinearLayoutManager(MainActivity.this);
        mRecyclerView.setLayoutManager(mDataLayoutManager);
        mDataAdapter = new DataAdapter(getDataSetData(), MainActivity.this);
        mRecyclerView.setAdapter(mDataAdapter);

        for (int i = 0; i < 10; i++) {
            DataObject obj = new DataObject(Integer.toString(i));
            resultsData.add(obj);
        }
        mDataAdapter.notifyDataSetChanged();
    }

    private ArrayList<DataObject> resultsData = new ArrayList<DataObject>();
    private List<DataObject> getDataSetData() {
        return resultsData;
    }
}
数据视图持有者:

package com.com.com;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

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

    public TextView mDataId;

    public DataViewHolders(View itemView) {
        super(itemView);
        itemView.setOnClickListener(this);

        mDataId = (TextView) itemView.findViewById(R.id.Dataid);
    }

    @Override
    public void onClick(View v) {

    }
}
主要活动:

<?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=".MainActivity"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/recyclerView"
            android:scrollbars="vertical">

        </androidx.recyclerview.widget.RecyclerView>
    </androidx.core.widget.NestedScrollView>

</LinearLayout>

项目u数据:

<?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:orientation="horizontal"
    android:padding="20sp">

    <ImageView
        android:layout_width="75sp"
        android:layout_height="75sp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Data ID"
        android:layout_gravity="center"
        android:id="@+id/Dataid" />

</LinearLayout>

您在这里返回了错误的值,它必须是列表的大小

您在这里返回了错误的值,它必须是列表的大小

<?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=".MainActivity"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/recyclerView"
            android:scrollbars="vertical">

        </androidx.recyclerview.widget.RecyclerView>
    </androidx.core.widget.NestedScrollView>

</LinearLayout>
<?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:orientation="horizontal"
    android:padding="20sp">

    <ImageView
        android:layout_width="75sp"
        android:layout_height="75sp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Data ID"
        android:layout_gravity="center"
        android:id="@+id/Dataid" />

</LinearLayout>
@Override
public int getItemCount() {
  return 0;
}