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.
Intent intent = ((Activity) context).getIntent();
intent.putExtra("SELECTED_PAYMENT", mCurrentlyCheckedRB
.getText().toString());
((Activity) context).setResult(((Activity) context).RESULT_OK,
intent);
((Activity) context).finish();
Solution 2:
public class MyAdapter extends ArrayAdapter
{
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
Intent yourIntent = new Intent();
Or:
Intent yourIntent = getIntent();
MyAdapter adapter = new MyAdapter(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) {
PaymentData rowItem = getItem(position);
LayoutInflater mInflater = (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"