从CustomArray的适配器调用的onActivityResult [英] calling onActivityResult from CustomArray adapter

查看:383
本文介绍了从CustomArray的适配器调用的onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的ListView自定义ArrayAdapter类,下面是code。

I have a class for custom ArrayAdapter for my ListView, below is the code.

public class CustomArrayAdapterForProduct extends ArrayAdapter<ProductClass> 
{
    private final Activity context;
    public final ArrayList<ProductClass> products;
    private static final int PICK_CONTACT = 1;

    public CustomArrayAdapterForProduct(Activity context, ArrayList<ProductClass> products) 
    {
        super(context, R.layout.product, products);
        this.context = context;
        this.products = products;
    }

    static class ViewHolder {
        protected TextView name;
        protected Button share;
        protected Button call;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {       
            View view = null;
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.product, parent,false);
            final ViewHolder viewHolder = new ViewHolder();
            final ProductClass file =   products.get(position);

            viewHolder.name = (TextView) view.findViewById(R.id.name);
            viewHolder.share = (Button) view.findViewById(R.id.videoView);
            viewHolder.call = (Button) view.findViewById(R.id.videoView);



            viewHolder.share.setOnClickListener(new OnClickListener() 
            {
                public void onClick(View v) 
                {
                  Intent intent = new Intent(Intent.ACTION_PICK,  Contacts.CONTENT_URI);
                  context.startActivityForResult(intent, PICK_CONTACT);
                }

            });


            viewHolder.name.setText(file.name.toString());
            view.setTag(viewHolder);

        return view;
    }
}

看这个 context.startActivityForResult(意向,PICK_CONTACT);
我如何定义我的的onActivityResult 在我的customArrayAdapter?

Look at this context.startActivityForResult(intent, PICK_CONTACT); how can i define my onActivityResult in my customArrayAdapter?

推荐答案

的onActivityResult(INT申请code,INT结果code,意图数据)是活动类方法不适用于任何Java类。

onActivityResult(int requestCode, int resultCode, Intent data) is Activity class method not for any JAVA class.

其只能用于Android的活动本身。

Its only works for Android Activity itself.

这篇关于从CustomArray的适配器调用的onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆