简体   繁体   English

使用 Recycler 视图调用 Api 加载更多

[英]Load More With Recycler view Calling Api

Hello i have Recycler view that get data from api ,, and all request give me 10 item ,, know i need to implement load more for this recycler and every scroll get another 10 item ,, i tried many times but its not working ,, please help this is my code您好,我有从 api 获取数据的 Recycler 视图,并且所有请求都给了我 10 个项目,知道我需要为该回收站实现更多加载,并且每次滚动都会获得另外 10 个项目,我尝试了很多次但它不起作用,,请帮助这是我的代码

Adapter适配器

   private int previousTotal = 0;
    private boolean loading = true;
    private int visibleThreshold = 0;
    int firstVisibleItem, visibleItemCount, totalItemCount;

 final LinearLayoutManager mLayoutManager = (LinearLayoutManager) mRecyclerView
                .getLayoutManager();

        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                visibleItemCount = mRecyclerView.getChildCount();
                totalItemCount = mLayoutManager.getItemCount();
                firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

                if (loading) {
                    if (totalItemCount > previousTotal) {
                        loading = false;
                        previousTotal = totalItemCount;
                    }
                }
                if (!loading && (totalItemCount - visibleItemCount)
                        <= (firstVisibleItem + visibleThreshold)) {
                    fragment.getHtmlNewsData("1");
                    loading = true;
                }
            }
        });

and here in activity在这里活动

     public void getHtmlNewsData(final String pageNumber) {
        BusinessManager.getNewsDataMethod(pageNumber, new ApiCallResponse() {
            @Override
            public void onSuccess(String StringResponse) {
                String Response = (String) StringResponse;
                try {
                    html = Response.toString();
                    String[] MainSperatedList = html.toString().split("<div class=\"views-field views-field-field-date\">");

                    final List<String> stringsDate = new ArrayList<String>();
                    for (int counter = 1; counter < MainSperatedList.length; counter++) {
                        String Text = MainSperatedList[counter].toString();
                        String ItemSelected = Jsoup.parse(Text).select("span.date-display-single").text();
                        stringsDate.add(ItemSelected);
                        Log.d("AAAAAAA", ItemSelected);
                    }

 mLayoutManager = new LinearLayoutManager(context);
                    recyclerViewNews.setLayoutManager(mLayoutManager);
                    newsReycelerViewAdapter = new NewsReycelerViewAdapter(recyclerViewNews, context, stringsDate, stringsTitle, stringsDetails, stringsImages, new JPANewsFragment());
                    recyclerViewNews.setAdapter(newsReycelerViewAdapter);
                    if (!pageNumber.equals("0"))
                    newsReycelerViewAdapter.notifyDataSetChanged();
}
}

this code its not working for me ,, if anyone have idea please tell me这段代码对我不起作用,如果有人有想法请告诉我

I've achive this by Using these two utils and call recyclerview method addOnScrollListener.我通过使用这两个实用程序并调用 recyclerview 方法 addOnScrollListener 来实现这一点。

First create these two utils in java package:首先在java包中创建这两个utils:

EndlessRecyclerOnScrollListener.java EndlessRecyclerOnScrollListener.java

package your.pakage.name;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();

private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;

private int current_page = 1;

private LinearLayoutManager mLinearLayoutManager;

public EndlessRecyclerOnScrollListener(LinearLayoutManager linearLayoutManager) {
    this.mLinearLayoutManager = linearLayoutManager;
}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

    if (loading) {
        if (totalItemCount > previousTotal) {
            loading = false;
            previousTotal = totalItemCount;
        }
    }
    if (!loading && (totalItemCount - visibleItemCount)
            <= (firstVisibleItem + visibleThreshold)) {
        // End has been reached

        // Do something
        current_page++;

        onLoadMore(current_page);

        loading = true;
    }
}

   public abstract void onLoadMore(int current_page);
 }

HidingScrollListener.java隐藏滚动监听器.java

package you.package.name;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;


public abstract class HidingScrollListener extends RecyclerView.OnScrollListener {

private static final int HIDE_THRESHOLD = 20;

private int mScrolledDistance = 0;
private boolean mControlsVisible = true;


@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    int firstVisibleItem = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();

    if (firstVisibleItem == 0) {
        if(!mControlsVisible) {
            onShow();
            mControlsVisible = true;
        }
    } else {
        if (mScrolledDistance > HIDE_THRESHOLD && mControlsVisible) {
            onHide();
            mControlsVisible = false;
            mScrolledDistance = 0;
        } else if (mScrolledDistance < -HIDE_THRESHOLD && !mControlsVisible) {
            onShow();
            mControlsVisible = true;
            mScrolledDistance = 0;
        }
    }
    if((mControlsVisible && dy>0) || (!mControlsVisible && dy<0)) {
        mScrolledDistance += dy;
    }
}

public abstract void onHide();
public abstract void onShow();
}

now after adding these two create your activity.java like this:现在在添加这两个之后创建您的activity.java,如下所示:

MyActivity.java我的活动.java

package your.package.name;


/**
 * Created by Admin on 9/26/2017.
 */

public class ProductFragment extends Fragment{
private ProductAdapter productAdapter;
private ProductLinearAdapter productLinearAdapter;
public static ArrayList<ProductModel> listProduct;
private RecyclerView mRecyclerviewProducts;
private boolean isGridView = false;
private AppBarLayout appBarLayout;
   // ProgressBar progressBar;
private ImageView iv_view;
private LinearLayout ll_sort,ll_filter;
private String checked=null;
private Button view_all;
RelativeLayout relativeLayout;
String category_id="";
HorizontalDotsProgressBar horizontalDotsProgressBar;
private String rupeeSymbol = "\u20B9";
//CardView cardView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_products,container,false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    horizontalDotsProgressBar = (HorizontalDotsProgressBar) view.findViewById(R.id.horizontalProgress);

    mRecyclerviewProducts = (RecyclerView) view.findViewById(R.id.rec_product_view);
    relativeLayout = (RelativeLayout) view.findViewById(R.id.rel_products);
    listProduct = new ArrayList<>();
    productAdapter = new ProductAdapter(getActivity(), listProduct);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),2);
    mRecyclerviewProducts.setLayoutManager(gridLayoutManager);
    DividerItemDecoration dividerAppliancesVer = new DividerItemDecoration(
            mRecyclerviewProducts.getContext(),
            DividerItemDecoration.VERTICAL
    );
    DividerItemDecoration dividerAppliancesHor = new DividerItemDecoration(
            mRecyclerviewProducts.getContext(),
            DividerItemDecoration.HORIZONTAL
    );
    dividerAppliancesVer.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shape_itemdecoration_vertical));
    dividerAppliancesHor.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shape_itemdecoration_horizontal));
    mRecyclerviewProducts.addItemDecoration(dividerAppliancesVer);
    mRecyclerviewProducts.addItemDecoration(dividerAppliancesHor);
    mRecyclerviewProducts.setAdapter(productAdapter);
    mRecyclerviewProducts.addOnScrollListener(new EndlessRecyclerOnScrollListener(gridLayoutManager) {
        @Override
        public void onLoadMore(int current_page) {
            uiUpdate(category_id,current_page-1,"");
        }
    });
    Bundle bundle = getArguments();
    if (bundle != null) {
        category_id = bundle.getString("category_id");
        if (!category_id.equalsIgnoreCase(null)) {
            Toast.makeText(getActivity(), category_id, Toast.LENGTH_SHORT).show();

            uiUpdate(category_id,0,"");
        }
    }


    mRecyclerviewProducts.addOnScrollListener(new HidingScrollListener() {
        @Override
        public void onHide() {
            hideViews();
        }

        @Override
        public void onShow() {
            showViews();
        }
    });

}
private void uiUpdate(final String category_id, final int pagenumber, final String price){

    final Snackbar snackbar = Snackbar.make(relativeLayout,"Products Loading...",Snackbar.LENGTH_SHORT);
    snackbar.show();
    //final ProgressDialog progressDialog=new ProgressDialog(getActivity());
    //progressDialog.show();
    StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://kibakibi.com/categoryproductapi?access_token=awerttshhjsekjkuy&categoryid=" + category_id+"&page="+pagenumber+"&price="+price,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {

                        Log.d("HomeFragment", "onResponse: " + response);
                        // Toast.makeText(getActivity(),response,Toast.LENGTH_SHORT).show();
                        JSONObject jsonRootObject = new JSONObject(response);
                        JSONArray jsonArray = jsonRootObject.getJSONArray("products");
                        String message = jsonRootObject.getString("message");
                        //progressDialog.dismiss();
                        snackbar.dismiss();
                        horizontalDotsProgressBar.clearAnimation();
                        horizontalDotsProgressBar.setVisibility(View.GONE);
                        //Toast.makeText(getActivity(),message,Toast.LENGTH_SHORT).show();
                        if(message.trim().equalsIgnoreCase("Success")){
                            //progressBar.setVisibility(View.GONE);

                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                String productId = jsonObject.optString("api_product_id");
                                String categoryId = jsonObject.optString("categoryId");
                                String product_Title = jsonObject.optString("productTitle");
                                String previousPrice =  jsonObject.optString("mrp");
                                String actualPrice = jsonObject.optString("expected_payout");
                                String sellerId = jsonObject.optString("seller_id");
                                String description = jsonObject.optString("description");
                                String imageurl = jsonObject.optString("product_images");
                                listProduct.add(new ProductModel(productId,product_Title,imageurl,categoryId,previousPrice,description,actualPrice,sellerId));
                            }
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    productAdapter.notifyItemRangeInserted(pagenumber*1,1);
                    //productAdapter.notifyDataSetChanged();

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Volley", "Error");

                }
            }
    );
    RetryPolicy retryPolicy = new DefaultRetryPolicy(30000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    stringRequest.setRetryPolicy(retryPolicy);
    VolleySingleton.getInstance(getActivity()).addToRequestQueue(stringRequest);
}

private void hideViews() {
   // cardView.animate().translationY(-cardView.getHeight()).setInterpolator(new AccelerateInterpolator(2));
}
private void showViews() {
   // cardView.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2));
}
}

And not a piece of change in the adapter but i'm gonna add it:而不是适配器中的一点变化,但我要添加它:

MyAdapter.java我的适配器

package your.package.name;



public class ProductAdapter extends 
RecyclerView.Adapter<ProductAdapter.MyViewHolder> {
    private ArrayList<ProductModel> list;
    private ArrayList<ProductModel> filterList;
    Context mContext;
    private static final int MAX_WIDTH = 400;
private static final int MAX_HEIGHT = 400;
int size = (int) Math.ceil(Math.sqrt(MAX_WIDTH * MAX_HEIGHT));
private String rupeeSymbol = "\u20B9";
public ProductAdapter(Context mContext, ArrayList<ProductModel> list) {
    this.list = list;
    this.filterList=list;
    this.mContext = mContext;
}

@Override
public ProductAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_products, parent, false);
    return new ProductAdapter.MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(final ProductAdapter.MyViewHolder holder, int position) {
    Typeface montserratregular = Typeface.createFromAsset(mContext.getAssets(), "font/montserratregular.ttf");
    final ProductModel productModel = filterList.get(position);
    //setting width & height
  /*  DisplayMetrics displayMetrics = new DisplayMetrics();
    ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int height = displayMetrics.heightPixels / 4;
    int width = (int) (displayMetrics.widthPixels * 0.9);
    holder.itemView.setLayoutParams(new LinearLayout.LayoutParams(width, height));*/
    holder.product_name.setText(productModel.getProduct_title());
    Picasso.with(mContext)
            .load(productModel.getProduct_imageFront())
            .transform(new BitmapTransForms(MAX_WIDTH, MAX_HEIGHT))
            .into(holder.product_image);
    holder.tv_actualPrice.setText(rupeeSymbol+productModel.getExpected_payout());
    holder.tv_previousPrice.setText(rupeeSymbol+productModel.getMrp());
    holder.tv_previousPrice.setPaintFlags(holder.tv_previousPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
   // holder.tv_percentOff.setText(productModel.getMargin());

    // Toast.makeText(mContext,productModel.getProduct_title(),Toast.LENGTH_LONG).show();
    holder.tv_actualPrice.setTypeface(montserratregular);
    holder.tv_previousPrice.setTypeface(montserratregular);
    holder.tv_percentOff.setTypeface(montserratregular);
    holder.tv_ratingNumber.setTypeface(montserratregular);
    holder.product_name.setTypeface(montserratregular);
    holder.tv_rating.setTypeface(montserratregular);
}

@Override
public int getItemCount() {

    return filterList.size();

}

class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    TextView product_name,tv_actualPrice,tv_previousPrice,tv_percentOff,tv_ratingNumber,tv_rating;
    ImageView product_image;
    MyViewHolder(View itemView) {
        super(itemView);
        product_name = (TextView) itemView.findViewById(R.id.tv_productname);
        product_image = (ImageView) itemView.findViewById(R.id.iv_products);
        tv_actualPrice = (TextView) itemView.findViewById(R.id.tv_actualPrice);
        tv_previousPrice = (TextView) itemView.findViewById(R.id.tv_previousPrice);
        tv_ratingNumber = (TextView) itemView.findViewById(R.id.tv_ratingNumber);
        tv_rating = (TextView) itemView.findViewById(R.id.tv_rating);
        tv_percentOff = (TextView) itemView.findViewById(R.id.tv_percentOff);
        itemView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        final ProductModel productModel = filterList.get(getAdapterPosition());
        Intent i = new Intent(mContext, SingleProductView.class);
        i.putExtra("image",productModel.getProduct_imageFront());
        i.putExtra("name",productModel.getProduct_title());
        i.putExtra("actualprice",productModel.getExpected_payout());
        i.putExtra("previousPrice",productModel.getMrp());
        i.putExtra("productId",productModel.getApi_product_id());
        Toast.makeText(mContext,productModel.getApi_product_id(),Toast.LENGTH_LONG).show();
        mContext.startActivity(i);
    }
}
}

It'll work for sure try it an on Youractivity.java pagenumber refer to paging like if your first page getting ten then after scroll it will increment and get the 2nd page value which now have 20 items on your recycler.它肯定会起作用,在 Youractivity.java pagenumber 指的是分页,就像你的第一页得到 10 然后滚动后它会增加并得到第二页值,现在你的回收器上有 20 个项目。 If have any problem tell me on comments i'll make them gone.如果有任何问题,请在评论中告诉我,我会让它们消失。

Use addOnScrollListener(OnScrollListener listener) from RecyclerView.java使用addOnScrollListener(OnScrollListener听众)RecyclerView.java

/**
 * Add a listener that will be notified of any changes in scroll state or position.
 *
 * <p>Components that add a listener should take care to remove it when finished.
 * Other components that take ownership of a view may call {@link #clearOnScrollListeners()}
 * to remove all attached listeners.</p>
 *
 * @param listener listener to set or null to clear
 */
public void addOnScrollListener(OnScrollListener listener)

Implementation:执行:

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy > 0 && loadingData) {
                visibleItemCount = layoutManager.getChildCount();
                totalItemCount = layoutManager.getItemCount();
                pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                    //loading flag set to false once data received for the scroll
                    loadingData = false;
                    //Network call using pagination information when scrolled
                    get(pagination, networkRequest);
                }
            }
        }
    });
    clearData();
    //Initial network call to get data from network
    get(pagination, networkRequest);
    **Adapter**

    public class ChooseTeamAdapter extends RecyclerView.Adapter<ChooseTeamAdapter.MyViewHolder> {


        public interface OnDeleteItemClickListener {

            public void onDeleteClicked();

        }

        OnDeleteItemClickListener onDeleteItemClickListener;

        private String TAG="ChooseTeamAdapter";
        Context context;
        private ArrayList<ChooseTeam.Featured> dataArrayList;
        ArrayList<String> arrayList = new ArrayList<String>();

        public static ArrayList<String> strCreditId=new ArrayList<>();

        public ChooseTeamAdapter(Context context, ArrayList<ChooseTeam.Featured> dataArrayList,OnDeleteItemClickListener monDeleteItemClickedListener) {
            this.context = context;
            this.dataArrayList = dataArrayList;
            this.onDeleteItemClickListener = monDeleteItemClickedListener;
        }

        @Override
        public ChooseTeamAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.list_item_team, parent, false);
            return new ChooseTeamAdapter.MyViewHolder(itemView);


        }

        @Override
        public void onBindViewHolder(final ChooseTeamAdapter.MyViewHolder holder, final int position) {

            holder.tvName.setText(dataArrayList.get(position).name);


            Picasso.with(context)
                    .load(dataArrayList.get(position).icon)
                    .placeholder(R.drawable.ndtv)
                    .into(holder.ivProfile);

            //click event for add
            holder.ivAdd.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    holder.ivAdd.setVisibility(View.GONE);
                    holder.ivChecked.setVisibility(View.VISIBLE);

                    //arrayList.add(dataArrayList.get(position).id);
                    strCreditId.add(dataArrayList.get(position).id);
                    Log.e(TAG,"ARRAYLIST SIZE==>"+strCreditId.size());

                    //onDeleteItemClickListener.onDeleteClicked();
                    Utils.WriteSharePrefrence(context, Constant.TEAM_NAME, strCreditId.toString().replace("[", "").replace("]", ""));

                }
            });

            //click event for ivChecked
            holder.ivChecked.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    holder.ivChecked.setVisibility(View.GONE);
                    holder.ivAdd.setVisibility(View.VISIBLE);

                    strCreditId.remove(dataArrayList.get(position).id);
                    Log.e(TAG,"ARRAYLIST SIZE==>"+strCreditId.size());
                    Utils.WriteSharePrefrence(context, Constant.TEAM_NAME, strCreditId.toString().replace("[", "").replace("]", ""));
                }
            });


        }

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

        public class MyViewHolder extends RecyclerView.ViewHolder {

            private TextView tvName;
            private ImageView ivProfile;
            private ImageView ivAdd;
            private ImageView ivChecked;


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

                tvName=itemView.findViewById(R.id.tv_teamname);
                ivProfile=itemView.findViewById(R.id.iv_team);
                ivAdd=itemView.findViewById(R.id.iv_add);
                ivChecked=itemView.findViewById(R.id.iv_checked);
            }
        }
    }



**Recyclerview**


    private String TAG = "ChooseTeamActivity";
    private Toolbar toolbar;
    private ProgressDialog progress;
    private RecyclerView rvTeam;
    private ArrayList<ChooseTeam.Featured> teamArrayList;
    private ChooseTeamAdapter chooseTeamAdapter;
    private TextView tvDone;
    private String teamid;


        getChooseteam();

 private void Hideprogress() {
        // TODO Auto-generated method stub
        if (progress.isShowing()) {
            progress.dismiss();
        }
    }

    private void ShowProgress() {
        // TODO Auto-generated method stub
        progress = new ProgressDialog(ChooseTeamActivity.this);
        progress.setMessage("Please wait...");
        progress.setCancelable(false);
        progress.show();
    }

    //API call for Chooseteam
    private void getChooseteam() {
        AsyncHttpClient client = new AsyncHttpClient();
        RequestParams requestParams = new RequestParams();
        Log.e(TAG, "CHOOSE_TEAM_URL==>" + Urls.TEAM_LIST + requestParams);
        client.post(Urls.TEAM_LIST, requestParams, new JsonHttpResponseHandler() {

            @Override
            public void onStart() {
                super.onStart();
                ShowProgress();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                Hideprogress();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                Log.e(TAG, "CHOOSE_TEAM_URL RESPONSE-" + response);

                if (response.equals("")) {
                    Toast.makeText(ChooseTeamActivity.this, "Something Wrong!", Toast.LENGTH_SHORT).show();
                } else {

                    if (!response.equals("")) {
                        ChooseTeam team = new Gson().fromJson(String.valueOf(response), ChooseTeam.class);
                        if (team.status.equals("true")) {
                            if (team.featuredArrayList.size() > 0) {
                                teamArrayList = team.featuredArrayList;
                                RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(ChooseTeamActivity.this, 1);
                                rvTeam.setLayoutManager(mLayoutManager);
                                chooseTeamAdapter = new ChooseTeamAdapter(ChooseTeamActivity.this, teamArrayList, ChooseTeamActivity.this);
                                rvTeam.setAdapter(chooseTeamAdapter);
                            } else {
                                Toast.makeText(ChooseTeamActivity.this, "Data Not Found!", Toast.LENGTH_SHORT).show();
                            }

                        } else {

                            Toast.makeText(ChooseTeamActivity.this, team.message, Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(ChooseTeamActivity.this, "something went wrong!", Toast.LENGTH_SHORT).show();
                    }
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Hideprogress();
                Toast.makeText(ChooseTeamActivity.this, "Something Wrong!", Toast.LENGTH_SHORT).show();
                Log.e(TAG, throwable.getMessage());
            }
        });

    }
**Library**

    implementation 'com.intuit.sdp:sdp-android:1.0.4'
 implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.google.code.gson:gson:2.2.4'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support:cardview-v7:26+'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'


**Choose team activity**

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_team"
        android:layout_below="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>





**list_item_team**

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/_5sdp"
    android:paddingRight="@dimen/_5sdp">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_team"
                android:layout_width="@dimen/_50sdp"
                android:layout_height="@dimen/_30sdp"
                android:layout_weight="0.1"
                android:layout_marginTop="@dimen/_10sdp"
                android:src="@drawable/ndtv" />

            <TextView
                android:id="@+id/tv_teamname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
               android:layout_gravity="center"
                android:layout_marginLeft="@dimen/_10sdp"
                android:layout_weight="1"
                android:text="Rockies"
                android:textColor="@color/black"
                android:textStyle="bold" />



            <ImageView
                android:id="@+id/iv_add"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_20sdp"
                android:layout_gravity="center"
                android:layout_weight="3"
                android:src="@drawable/ic_add" />


            <ImageView
                android:id="@+id/iv_checked"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_30sdp"
                android:layout_gravity="center"
                android:layout_weight="3"
                android:src="@drawable/ic_checked"
                android:visibility="gone"

                />



        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:background="#E4E4E4"
            android:layout_marginTop="@dimen/_4sdp"
            ></View>
    </LinearLayout>
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM