В классе адаптера пользователь может захватывать изображение при нажатии holder.image
.Я установил onActivityResult
во фрагменте, но он не вызывается.
Фрагмент
grid.setAdapter(ImageListAdapter(getActivity(), listOfImagesPath))
....
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
val mAdapter: ImageListAdapter?=null
mAdapter?.onActivityResult(requestCode, resultCode, data);
longToast("abc")
var bitmap: Bitmap? = null
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
longToast("hello")
} else {
longToast("bye")
}
}
Адаптер
class ImageListAdapter(
private val context: FragmentActivity?,
private val imgPics: List<String>?
) : BaseAdapter() {
override fun getItem(position: Int): Any {
return position
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getCount(): Int {
if (imgPics != null)
return imgPics.size
else
return 1;
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var holder: ItemHolder
var convertView = convertView
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.grid_item, null)
holder = ItemHolder()
holder.image = convertView!!.findViewById(R.id.imageView)
holder.image?.setImageResource(R.drawable.ic_add)
holder.image?.setColorFilter(R.color.colorGainsboro, PorterDuff.Mode.SRC_ATOP);
convertView.tag = holder
}
holder = convertView?.tag as ItemHolder
....
holder.image?.setImageBitmap(bm)
}
}
holder.image?.setOnClickListener{
dispatchTakePictureIntent()
}
return convertView
}
private fun dispatchTakePictureIntent() {
try {
val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE);
context?.startActivityForResult(captureIntent, 1);
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
}
}
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
Log.e("MyAdapter", "onActivityResult")
}
internal class ItemHolder {
var image: ImageView? = null
}
}
У кого-нибудь есть идея?