Start Intent in Adapter

前端 未结 8 1773
清酒与你
清酒与你 2021-02-02 13:32

I want to start a new activity from this base adapter.

public class EfficientAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList         


        
8条回答
  •  甜味超标
    2021-02-02 14:05

    Pass activity context from activity and use same context while calling Intent.

    From activity:

    yourview.setAdapter(new EfficientAdapter(this));
    

    within adapter:

     private Context mContext;
    
    
      public EfficientAdapter(Context c) {
            mContext = c;
    
        }
    

    Now use mContext to call Intent.

    startActivity(new Intent(mContext, NVirementEmmeteur.class));
    

提交回复
热议问题