onActivityResult在不叫的类从ArrayAdapter扩展 [英] onActivityResult in not called in the class extended from ArrayAdapter
问题描述
我没有搜索,但无法找到在互联网上有用的答案。这就是为什么我提出查询。
我喜欢加载摄像头和捕捉图像中的自定义一个ArrayAdapter类的 getView
方法。摄像头是装和捕捉图像,但 onActivityResult()
永远不会被调用。我的code为如下图所示。
I did search but can't find useful answer in the internet. That is why I raise the query.
I like to load the camera and capture image in the getView
method of a custom ArrayAdapter class. Camera is loaded and capture image but onActivityResult()
is never called. My code is as shown below.
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
ViewHolder viewHolder=new ViewHolder();
LayoutInflater inflater = (LayoutInflater) this.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(vi==null){
vi = inflater.inflate(R.layout.list_row, parent, false);
viewHolder.id=(TextView)vi.findViewById(R.id.title);
viewHolder.thumbnailImage=(ImageView)vi.findViewById(R.id.list_image);
viewHolder.arrow=(ImageView)vi.findViewById(R.id.list_arrow);
vi.setTag(viewHolder);
}
else
viewHolder=(ViewHolder) vi.getTag();
// Setting all values in listview
viewHolder.id.setText(listIDs.get(position));
viewHolder.thumbnailImage.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity)context).startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
return vi;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
// Bitmap photo = (Bitmap) data.getExtras().get("data");
// imageView.setImageBitmap(photo);
}
}
然后自定义适配器类是从 ListFragment
类激活为
customList_Adaptor adapter = new customList_Adaptor(
getActivity(), R.layout.list_row, listIDs);
我要如何让onActivityResult()方法被调用。 谢谢
How can I modify so that onActivityResult() method is called. Thanks
推荐答案
onActivityResult
属于活动
。您可以在 Actvity / ListActivity
情况下只覆盖。你可以做的就是保持一个引用 Actvity / ListActivity
在你ArrayAdapter的子类,创建一个方法里面调用时 onActivityResult
被激发和条件都满足
onActivityResult
belongs to the Activity
. You can override only in the Actvity/ListActivity
context. What you can do is to keep a reference to your ArrayAdapter's subclass inside the Actvity/ListActivity
, create a method inside it to invoke when onActivityResult
is fired and condition are met
这篇关于onActivityResult在不叫的类从ArrayAdapter扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!