3

在 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;
}
4

4 回答 4

19

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();
于 2013-04-22T10:07:57.927 回答
3
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
    }

在您的活动中使用第二个构造函数创建您的适配器类的对象

Intent yourIntent = new Intent(); 

或者:

Intent yourIntent = getIntent();
MyAdapter adapter = new MyAdapter(context,yourIntent); // here pass intent
于 2013-04-22T08:43:13.903 回答
0

在适配器类中,您传递活动实例并使用 Context 变量捕获它。下面的片段会帮助你,

私有上下文 mcontext;

private Intent adapintent;

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

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

}
于 2013-04-22T09:05:47.660 回答
-1

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

PaymentData rowItem = getItem(position);


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

{

//你可以包含这个 :context.getintent(); }

于 2013-04-22T08:49:56.410 回答