Java 回收商';不调用的自定义适配器方法

Java 回收商';不调用的自定义适配器方法,java,android,xml,android-recyclerview,android-cardview,Java,Android,Xml,Android Recyclerview,Android Cardview,我在布局中使用其他布局元素和recyclerview,并在oncreateViewHolder(自定义适配器)中扩展cardview布局。方法仅在我仅在布局中使用recyclerview而不使用其他布局元素时调用 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width

我在布局中使用其他布局元素和recyclerview,并在oncreateViewHolder(自定义适配器)中扩展cardview布局。方法仅在我仅在布局中使用recyclerview而不使用其他布局元素时调用

<?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="match_parent">         
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_layout_for_item_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
android:id="@+id/detail_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/detail_category_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textStyle="bold"
android:layout_below="@+id/detail_category_price" />

<TextView
android:id="@+id/detail_category_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Rs: 1000" />

<Button
android:id="@+id/btn_bid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bid"
android:textColor="@color/colorPrimary"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/detail_category_price"
android:layout_margin="10dp"/>
<GridView
android:id="@+id/grid_view"
android:layout_below="@+id/btn_bid"
android:columnWidth="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</GridView>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:id="@+id/view"
android:layout_marginTop="5dp"
android:layout_below="@+id/grid_view"
android:background="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="About the seller"
android:layout_margin="5dp"
android:textSize="20sp"
android:textColor="@color/orange"
android:id="@+id/about_seller"
android:layout_below="@+id/view"
/>

<TextView
android:id="@+id/seller_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="username: bilal"
android:layout_margin="5dp"
android:layout_below="@+id/about_seller"/>
<Button
android:id="@+id/contact_seller_button"
android:text="contact button"
android:layout_margin="5dp"
android:layout_below="@+id/seller_user_name"
android:textColor="@color/colorPrimary"
android:shadowColor="@color/orange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="@+id/bids_recycler_view"
android:layout_width="match_parent"
android:layout_below="@+id/detail_card_view"
android:layout_height="200dp"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_margin="5dp"
android:id="@+id/card_view"
android:layout_gravity="center"
android:background="@android:color/white"
app:cardElevation="2sp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<TextView
android:id="@+id/bid_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10000"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/bidder_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bidder Name"
android:textStyle="italic"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_below="@+id/bid_text_View"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</ScrollView>

这是我正在膨胀的布局

<android.support.v7.widget.CardView
android:layout_margin="5dp"
android:id="@+id/card_view"
android:layout_gravity="center"
android:background="@android:color/white"
app:cardElevation="2sp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<TextView
android:id="@+id/bid_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10000"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/bidder_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bidder Name"
android:textStyle="italic"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_below="@+id/bid_text_View"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</ScrollView>

<android.support.v7.widget.CardView
android:layout_margin="5dp"
android:id="@+id/card_view"
android:layout_gravity="center"
android:background="@android:color/white"
app:cardElevation="2sp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<TextView
android:id="@+id/bid_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10000"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/bidder_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bidder Name"
android:textStyle="italic"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_below="@+id/bid_text_View"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</ScrollView>
这是活动代码->

<android.support.v7.widget.CardView
android:layout_margin="5dp"
android:id="@+id/card_view"
android:layout_gravity="center"
android:background="@android:color/white"
app:cardElevation="2sp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<TextView
android:id="@+id/bid_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10000"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/bidder_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bidder Name"
android:textStyle="italic"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_below="@+id/bid_text_View"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</ScrollView>
private RecyclerView mRecyclerView;
private SwipeRefreshLayout mSwipeRefreshLayout;
private BidsAdapter mBidsAdapter;
private ArrayList<String> arrayList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item_detials);
    String detail = getIntent().getStringExtra(AppGlobals.detial);
    setTitle(detail);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView =    (RecyclerView)findViewById(R.id.bids_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout_for_item_detail);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.orange, R.color.green,
            R.color.colorPrimary, R.color.gray);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mSwipeRefreshLayout.setRefreshing(false);
        }
    });
    mRecyclerView.setLayoutManager(linearLayoutManager);
    mRecyclerView.canScrollVertically(LinearLayoutManager.VERTICAL);
    bitmapArrayList = new ArrayList<>();
    arrayList = new ArrayList<>();
    arrayList.add("test one");
    arrayList.add("test two");
    arrayList.add("test three");
    arrayList.add("test four");
    arrayList.add("test five");
}

 @Override
protected void onResume() {
    super.onResume();
    mBidsAdapter = new BidsAdapter(arrayList);
    mRecyclerView.setAdapter(mBidsAdapter);
    System.out.println(mRecyclerView == null);
    System.out.println(mBidsAdapter == null);
    mRecyclerView.addOnItemTouchListener(new BidsAdapter(arrayList, getApplicationContext()
            , new BidsAdapter.OnItemClickListener() {
        @Override
        public void onItem(String item) {
            System.out.println(item);
        }
    }));
    System.out.println("DONE");

}
static class BidsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements
        RecyclerView.OnItemTouchListener {

    private OnItemClickListener mListener;
    private GestureDetector mGestureDetector;
    private BidView bidView;
    private ArrayList<String> items;

    public interface OnItemClickListener {
        void onItem(String item);
    }

    public BidsAdapter(ArrayList<String> data) {
        super();
        this.items = data;
    }

    public BidsAdapter(ArrayList<String> categories, Context context, OnItemClickListener listener) {
        this.items = categories;
        mListener = listener;
        mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                return true;
            }
        });
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        System.out.println("beforeView");
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.bids_layout, parent, false);
        System.out.println(view == null);
        bidView = new BidView(view);
        System.out.println("WORKING");
        return bidView;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        bidView.textView.setText(String.valueOf(position));
        bidView.bidderTextView.setText(items.get(position));
        System.out.println(position);
    }

    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
        View childView = rv.findChildViewUnder(e.getX(), e.getY());
        if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
            mListener.onItem(items.get(rv.getChildPosition(childView)));
            return true;
        }
        return false;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {

    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }

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

static class BidView extends RecyclerView.ViewHolder {
    public TextView textView;
    public TextView bidderTextView;

    public BidView(View itemView) {
        super(itemView);
        textView = (TextView) itemView.findViewById(R.id.bid_text_View);
        bidderTextView = (TextView) itemView.findViewById(R.id.bidder_user_name);
    }
}  
private RecyclerView mRecyclerView;
私人SwipeRefreshLayout mSwipeRefreshLayout;
专用BidsAdapter mBidsAdapter;
私有ArrayList ArrayList;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.item_detials);
String detail=getIntent().getStringExtra(AppGlobals.detial);
片名(细节);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mRecyclerView=(RecyclerView)findViewById(R.id.bids\u recycler\u view);
mRecyclerView.setHasFixedSize(true);
LinearLayoutManager LinearLayoutManager=新的LinearLayoutManager(此);
mSwipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.swipe_layout_查看项目详细信息);
mSwipeRefreshLayout.setColorSchemeResources(R.color.orange、R.color.green、,
R.color.colorPrimary,R.color.gray);
mSwipeRefreshLayout.setOnRefreshListener(新的SwipeRefreshLayout.OnRefreshListener()){
@凌驾
公共void onRefresh(){
mSwipeRefreshLayout.setRefresh(false);
}
});
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.canscrollvertical(LinearLayoutManager.VERTICAL);
bitmapArrayList=新建ArrayList();
arrayList=新的arrayList();
添加(“测试一”);
添加(“测试二”);
添加(“测试三”);
添加(“测试四”);
arrayList.添加(“测试五”);
}
@凌驾
受保护的void onResume(){
super.onResume();
mBidsAdapter=新的BidsAdapter(arrayList);
mRecyclerView.setAdapter(mBidsAdapter);
System.out.println(mRecyclerView==null);
System.out.println(mBidsAdapter==null);
addonitemtouchlister(新的BidsAdapter(arrayList,getApplicationContext())
,new BidsAdapter.OnItemClickListener(){
@凌驾
公共无效项(字符串项){
系统输出打印项次(项);
}
}));
系统输出打印项次(“完成”);
}
静态类BidsAdapter扩展了RecyclerView。适配器实现
RecyclerView.OnItemTouchListener{
私人监听者;
私人手势检测器mGestureDetector;
私人BidView BidView;
私有ArrayList项;
公共接口侦听器{
无效项(字符串项);
}
公开招标文件(ArrayList数据){
超级();
此项=数据;
}
公共BidsAdapter(ArrayList类别、上下文上下文、侦听器){
此项=类别;
mListener=监听器;
mGestureDetector=new GestureDetector(上下文,new GestureDetector.SimpleOnGestureListener()){
@凌驾
公共布尔onSingleTapUp(运动事件e){
返回true;
}
});
}
@凌驾
public RecyclerView.ViewHolder onCreateViewHolder(视图组父级,int-viewType){
System.out.println(“beforeView”);
View=LayoutFlater.from(parent.getContext()).flate(R.layout.bids\u layout,parent,false);
System.out.println(视图==null);
bidView=新bidView(视图);
系统输出打印(“工作”);
返回bidView;
}
@凌驾
BindViewHolder上的公共无效(RecyclerView.ViewHolder,int位置){
bidView.textView.setText(String.valueOf(position));
bidView.bidderTextView.setText(items.get(position));
系统输出打印项次(位置);
}
@凌驾
公共布尔值onInterceptTouchEvent(RecyclerView rv,MotionEvent e){
View childView=rv.findChildViewUnder(e.getX(),e.getY());
if(childView!=null&&mListener!=null&&mGestureDetector.onTouchEvent(e)){
mListener.onItem(items.get(rv.getChildPosition(childView));
返回true;
}
返回false;
}
@凌驾
公共活动(RecyclerView rv、MotionE){
}
@凌驾
OnRequestDisallowinetCeptTouchEvent上的公共无效(布尔值DisallowinetCept){
}
@凌驾
public int getItemCount(){
返回items.size();
}
}
静态类BidView扩展了RecyclerView.ViewHolder{
公共文本视图文本视图;
公共文本视图投标人文本视图;
公共视图(视图项视图){
超级(项目视图);
textView=(textView)itemView.findViewById(R.id.bid\u text\u View);
bidderTextView=(TextView)itemView.findViewById(R.id.bidder\u用户名);
}
}  
是否替换此

<android.support.v7.widget.CardView
android:layout_margin="5dp"
android:id="@+id/card_view"
android:layout_gravity="center"
android:background="@android:color/white"
app:cardElevation="2sp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<TextView
android:id="@+id/bid_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10000"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/bidder_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bidder Name"
android:textStyle="italic"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_below="@+id/bid_text_View"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</ScrollView>
static class BidsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements
    RecyclerView.OnItemTouchListener {
静态类BidsAdapter扩展了RecyclerView。适配器实现
RecyclerView.OnItemTouchListener{
反而

<android.support.v7.widget.CardView
android:layout_margin="5dp"
android:id="@+id/card_view"
android:layout_gravity="center"
android:background="@android:color/white"
app:cardElevation="2sp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="200dp">
<RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

<TextView
android:id="@+id/bid_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10000"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/bidder_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bidder Name"
android:textStyle="italic"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_below="@+id/bid_text_View"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</ScrollView>
static class BidsAdapter extends RecyclerView.Adapter<BidsAdapter.BidView> implements
    RecyclerView.OnItemTouchListener { 
静态类BidsAdapter扩展了RecyclerView。适配器实现
RecyclerView.OnItemTouchListener{

您将BidView类放在哪里?在适配器中还是在主类中?