将布局扩大为适配器

时间:2018-10-05 17:18:47

标签: android

下面是回收站适配器的代码,此处将适配器绑定到选项卡。问题是标签布局不会膨胀

package in.squareconnect.adapters;

import android.content.Context;
import android.content.Intent;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.squareup.picasso.Picasso;

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

import in.squareconnect.R;
import in.squareconnect.activities.EventDetailsActivity;
import in.squareconnect.databinding.ActivityEventBinding;
import in.squareconnect.datamodels.CommonViewModel;
import in.squareconnect.datamodels.dummymodel;
import in.squareconnect.utils.OnRecyclerViewItemClickListener;
import in.squareconnect.widgets.AppImageView;
import in.squareconnect.widgets.AppViewPager;
import in.squareconnect.widgets.CommonSlidingTabLayout;


public class EventListingAdapter extends RecyclerView.Adapter<EventListingAdapter.EventViewHolder> {


    List<dummymodel> projectLists;
    private OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;
    CommonViewModel model;
    private Context context;


    public EventListingAdapter(List<dummymodel> projectList, CommonViewModel model) {
        this.projectLists = projectList;
        this.model = model;
    }

    public void addList(List<dummymodel> projectList) {
        this.projectLists.addAll(projectList);
    }

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


    @Override
    public EventViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        ActivityEventBinding mActivityEventBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.activity_event, parent, false);


        this.context = parent.getContext();
        return new EventViewHolder(mActivityEventBinding);
    }

    @Override
    public void onBindViewHolder(EventViewHolder holder, int position) {
        holder.bindData(holder, projectLists.get(position), model);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }


    @BindingAdapter("android:src")
    public static void setImageUrl(AppImageView view, String url) {
        if (!TextUtils.isEmpty(url)) {
            Picasso.with(view.getContext()).load(url).into(view);
        }
    }

    public void clearList() {
        this.projectLists.clear();
    }

    public class EventViewHolder extends RecyclerView.ViewHolder {


        private ActivityEventBinding mactivityeventbinding;
        public CommonSlidingTabLayout statesTabStrip;
        public AppViewPager vwpgr_states;
        public EventsAdapter adapter;

        public EventViewHolder(ActivityEventBinding mactivityeventbinding) {
            super(mactivityeventbinding.getRoot());
            this.mactivityeventbinding = mactivityeventbinding;

            statesTabStrip = mactivityeventbinding.getRoot().findViewById(R.id.statesTabStrip);
            statesTabStrip.setDistributeEvenly(true);
            statesTabStrip.setSelectedIndicatorColors(Color.parseColor("#ff8800"));
            vwpgr_states = mactivityeventbinding.getRoot().findViewById(R.id.vwpgr);


        }

        public void bindData(EventViewHolder holder, dummymodel dummyobj, CommonViewModel model) {

            ArrayList<String> statestitle = new ArrayList<>();
            statestitle.add("Noida");
            statestitle.add("gurgaon");


//            EventsAdapter adapter = holder.adapter;

//            adapter.adddata(statestitle, new ArrayList<dummymodel>());
            adapter = new EventsAdapter(context, statestitle, new ArrayList<dummymodel>());


            vwpgr_states.setAdapter(adapter);

在这里,我将标签适配器设置为绑定,但布局不会膨胀,直到我滚动到屏幕底部并再次在标签之间切换

            statesTabStrip.setViewPager(vwpgr_states);


            mactivityeventbinding.getRoot().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    fetchParticulareventDetails();
                }
            });
        }


        public void fetchParticulareventDetails() {
//
            Intent in = new Intent(context, EventDetailsActivity.class);
            context.startActivity(in);
//
//
        }

    }

}

0 个答案:

没有答案