У меня есть собственный список, который включает текстовое представление, флажок и изображение. Если флажок установлен, текстовое представление и изображение будут видны. Когда я нажимаю textView, я делаю фотографию и отображаю ее в виде изображения. Поскольку я не могу вызвать onActivityResult в адаптере, поэтому я вызываю его в Activity и хочу отправить позицию объекта в listView из адаптера в активность, но он отправляет ошибку, что позиция, которую я получаю в MainActivity, равна нулю. Итак, как я могу это решить?
Вот мой файл .xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingRight="10dp"
android:paddingLeft="16dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_instore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:layout_centerVertical="true"
android:text="Product"
android:textSize="14sp"
android:layout_weight="1"/>
<CheckBox
android:id="@+id/chk_instore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_weight="1"
android:checked="false"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Capture"
android:visibility="invisible"
android:id="@+id/txtCapture"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img1"
android:layout_weight="1"
android:paddingTop="5dp"
android:visibility="invisible"/>
</LinearLayout>
Here is in adapter:
txtCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra("position",position);
((Activity) mContext).startActivityForResult(i, 100);
}
}
});
Вот мой onActivityResult() в MainActivity:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==100&&resultCode==RESULT_OK){
Bitmap b = (Bitmap)data.getExtras().get("data");
int position = (int)data.getExtras().get("position");
POSMQty p = arrPOSMInstore.get(position);
p.setBitmap(b);
}
}