RecyclerView仅显示10个项目

时间:2018-05-02 18:13:41

标签: java android

我为读取rss文章做了一个应用程序,我不知道为什么我的应用程序只显示recyclerview中的10个项目,在包含更多10个项目的文件中。

将来我会在多个网站上实施我的应用程序搜索,并且有10个项目我无法做到这一点

我的活动

public class InicioFragment 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 RecyclerView recyclerViewListaNoticias;
RSSObject rssObject;


private final String RSS_link="http://fetchrss.com/rss/5ae2b84f8a93f8de6b8b4567541927788.atom";
private final String RSS_to_Json_API = " https://api.rss2json.com/v1/api.json?rss_url=";

private OnFragmentInteractionListener mListener;

public InicioFragment() {
    // Required empty public constructor
}

public static InicioFragment newInstance(String param1, String param2) {
    InicioFragment fragment = new InicioFragment();
    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 view = inflater.inflate(R.layout.fragment_inicio, container, false);

    //RecyclerView Lista Configs

    recyclerViewListaNoticias = view.findViewById(R.id.recyclerviewnoticias);

    //Configurar Adapter



    //Configurar RecyclerView
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerViewListaNoticias.setLayoutManager(layoutManager);
    recyclerViewListaNoticias.setHasFixedSize(true);
    //recyclerViewListaNoticias.setAdapter( );



    loadRSS();



    return view;
}

private void loadRSS(){
    AsyncTask<String,String,String> loadRSSAsync = new AsyncTask<String, String, String>() {

        ProgressDialog mDialog = new ProgressDialog(getActivity());

        @Override
        protected void onPreExecute() {
            mDialog.setMessage("Aguarde um momento...");
            mDialog.show();
        }

        @Override
        protected String doInBackground(String... params) {
            String result;
            HTTPDataHandler http = new HTTPDataHandler();
            result = http.GetHTTPData(params[0]);
            return result;
        }

        @Override
        protected void onPostExecute(String s) {
            mDialog.dismiss();
            rssObject = new Gson().fromJson(s, RSSObject.class);
            FeedAdapter adapter = new FeedAdapter(rssObject, getActivity());
            recyclerViewListaNoticias.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }
    };

    StringBuilder url_get_data = new StringBuilder(RSS_to_Json_API);
    url_get_data.append(RSS_link);
    loadRSSAsync.execute(url_get_data.toString());

}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId() == R.id.menu_refresh)
        loadRSS();
    return true;
}




public void onButtonPressed(Uri uri) {
    if (mListener != null) {
        mListener.onFragmentInteraction(uri);
    }
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof OnFragmentInteractionListener) {
        mListener = (OnFragmentInteractionListener) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}

@Override
public void onDetach() {
    super.onDetach();
    mListener = null;
}

public interface OnFragmentInteractionListener {
    // TODO: Update argument type and name
    void onFragmentInteraction(Uri uri);
}

}

这是我的适配器,在这里我为网站上的应用程序搜索定义了itens。

public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.FeedViewHolder>{
private RSSObject rssObject;
private Context mContext;
private LayoutInflater inflater;


public FeedAdapter(RSSObject rssObject, Context mContext) {
    this.rssObject = rssObject;
    this.mContext = mContext;
    inflater = LayoutInflater.from(mContext);

}

@NonNull
@Override
public FeedViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View itemView = inflater.inflate(R.layout.cardviewistanoticiasmodelo,parent,false);
    return new FeedViewHolder(itemView);
}

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

    holder.txtTitle.setText(rssObject.getItems().get(position).getTitle());
    holder.txtPubDate.setText(rssObject.getItems().get(position).getPubDate());
    holder.txtAuthor.setText(rssObject.getItems().get(position).getAuthor());
    holder.imgNoticias.setImageURI(Uri.parse(rssObject.getItems().get(position).getThumbnail()));





}

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



class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener{

    public TextView txtTitle,txtPubDate,txtAuthor;
    private ItemClickListener itemClickListener;
    public ImageView imgNoticias;

    public FeedViewHolder(View itemView) {
        super(itemView);

        txtTitle = (TextView)itemView.findViewById(R.id.tituloNoticia);
        txtPubDate = (TextView)itemView.findViewById(R.id.textPubDate);
        txtAuthor = (TextView)itemView.findViewById(R.id.autorNoticia);
        imgNoticias = (ImageView)itemView.findViewById(R.id.imagemNoticia);

        itemView.setOnClickListener(this);
        itemView.setOnLongClickListener(this);
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }


    @Override
    public void onClick(View v) {

        itemClickListener.onClicl(v,getAdapterPosition(),false);
    }

    @Override
    public boolean onLongClick(View v) {
        itemClickListener.onClicl(v,getAdapterPosition(),true);
        return true;
    }
}

0 个答案:

没有答案