Android 如何在适配器类中调用getIntent()

Android 如何在适配器类中调用getIntent(),android,listview,android-intent,Android,Listview,Android Intent,在getView()方法中,我想调用getIntent()。如何在不开始新活动的情况下实现这一点。像这样的getView方法 public View getView(final int position, View convertView, ViewGroup parent) { PaymentData rowItem = getItem(position); LayoutInflater mInflater = (LayoutInflater) context

在getView()方法中,我想调用getIntent()。如何在不开始新活动的情况下实现这一点。像这样的getView方法

public View getView(final int position, View convertView, ViewGroup parent) {
    PaymentData rowItem = getItem(position);
    LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(
                com.android.paypal.homeactivity.R.layout.list_item, null);
        holder = new ViewHolder();
        holder.radioBtn = (RadioButton) convertView
                .findViewById(com.android.paypal.homeactivity.R.id.rdb_payment_method);
        convertView.setTag(holder);
    } else
        holder = (ViewHolder) convertView.getTag();

    if (position == getCount() - 1 && userSelected == false) {
        holder.radioBtn.setChecked(true);
        mCurrentlyCheckedRB = holder.radioBtn;
    } else {
        holder.radioBtn.setChecked(false);
    }

    holder.radioBtn.setText(rowItem.getRdbText());
    return convertView;
}
在活动中使用第二个构造函数创建适配器类的对象

Intent yourIntent = new Intent(); 
或:

公共视图getView(最终整数位置、视图转换视图、视图组父视图){

{

//您可以包括以下内容:context.getintent();
}

在适配器类中,您传递活动实例并使用上下文变量捕获它。 下面的代码片段将帮助您

私有上下文

private Intent adapintent;

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

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

}

这是这个问题的解决办法

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

您可以将数据传递给适配器的构造函数。实际上,当用户单击“当前”按钮时,我希望将数据传递给另一个活动,而不创建新的活动。try((activity)view.getContext()).getIntent(),其中在适配器类中查看它itemView
PaymentData rowItem = getItem(position);


LayoutInflater mInflater = (LayoutInflater) context
        .getSystemService(Context.getintent().LAYOUT_INFLATER_SERVICE);
private Intent adapintent;

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

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

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