Skip to content Skip to sidebar Skip to footer

How To Call Getintent() In Adapter Class

In getView() method I want to call getIntent(). How can I achieve this without starting a new activity. The getView method like this public View getView(final int position, View c

Solution 1:

Here is the solution of this problem.

Intentintent= ((Activity) context).getIntent();
            intent.putExtra("SELECTED_PAYMENT", mCurrentlyCheckedRB
                    .getText().toString());
            ((Activity) context).setResult(((Activity) context).RESULT_OK,
                    intent);
            ((Activity) context).finish();

Solution 2:

publicclassMyAdapterextendsArrayAdapter
{
    private Context context;
    private Intent intent;

    MyAdapter(Context context)
    {
        this.context = context;
    }

    MyAdapter(Context context,Intent intent)
    {
       this(context);
       this.intent = intent; // use this intent
    }

    private View getView()
    {
        // use intent here
    }

Create Object of your Adapter class using 2nd constructor in your activity

IntentyourIntent=newIntent(); 

Or:

IntentyourIntent= getIntent();
MyAdapteradapter=newMyAdapter(context,yourIntent); // here pass intent

Solution 3:

In adapter class you pass the activity instance and catch it with a Context variable. Below snippet will help you,

private Context mcontext;

private Intent adapintent;

MyIntentAdapter(Context context){
    this.mcontext = context;
}

MyIntentAdapter(Context context,Intent intent){
   this(context);
   this.adapintent= intent;

}

Solution 4:

public View getView(final int position, View convertView, ViewGroup parent) {

PaymentDatarowItem= getItem(position);


LayoutInflatermInflater= (LayoutInflater) context
        .getSystemService(Context.getintent().LAYOUT_INFLATER_SERVICE);

{

//you can include this :context.getintent(); }

Post a Comment for "How To Call Getintent() In Adapter Class"