繁体   English   中英

从CustomArray适配器调用onActivityResult

[英]calling onActivityResult from CustomArray adapter

我有一个用于ListView的自定义ArrayAdapter的类,下面是代码。

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(intent, PICK_CONTACT); 如何在我的customArrayAdapter中定义onActivityResult

onActivityResult(int requestCode, int resultCode, Intent data)是Activity类方法,不适用于任何JAVA类。

它仅适用于Android Activity本身。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM