0

访客详情

我在访客活动中有一个对话框。当我单击该图标时,它将重定向到相机活动。然后当点击相机活动中的确认按钮时,它会将意图发送回之前的活动,即访客活动。问题是我应该如何将相机活动的意图结果传递回访客活动中的对话框。意图数据应放置在 Pass No Edit Text 中。我正在使用没有附加到该对话框的任何片段的材质对话框。这一切都放在访客活动中。有人可以帮帮我吗?谢谢!

private void checkin()
{
    final MaterialDialog dialog = new MaterialDialog.Builder(VisitorDetailActivity.this)
            .customView(R.layout.sample,false)
            .build();

    View view = dialog.getCustomView();
    final EditText etPassNo = (EditText) view.findViewById(R.id.etPassNo);
    final EditText etVehicleNo = (EditText) view.findViewById(R.id.etVehicleNo);
    final ImageView ivScanCode = (ImageView) view.findViewById(R.id.ivScanCode);
    final TextView tvCancel = (TextView) view.findViewById(R.id.tvCancel);
    final TextView tvSubmit = (TextView) view.findViewById(R.id.tvSubmit);

    etVehicleNo.setText(model.getFldVehicleNo());

    if(barCode != null)
    {
        etPassNo.setText(barCode);
    }

    ivScanCode.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            //Toast.makeText(VisitorDetailActivity.this, "Bar code scanner", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(VisitorDetailActivity.this, ScanCodeActivity.class);
            startActivityForResult(i,97);
        }
    });

    tvCancel.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            dialog.dismiss();
        }
    });

    tvSubmit.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            if(etPassNo.getText().toString().trim().isEmpty())
            {
                Toast.makeText(VisitorDetailActivity.this, "Pass No is required", Toast.LENGTH_SHORT).show();
                return;
            }
            if(selImage == null)
            {
                proceedCheckin(etPassNo.getText().toString(), etVehicleNo.getText().toString());
            }
            else
            {
                proceedCheckinImage(etPassNo.getText().toString(), etVehicleNo.getText().toString());
            }
        }
    });

    dialog.show();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == 98 && resultCode == RESULT_OK)
    {
        selImage = data.getStringExtra("photo");

        Glide.with(VisitorDetailActivity.this).load(selImage).into(iDrivingLicense);

    }
    else if (requestCode == 99 && resultCode == RESULT_OK)
    {
        selImage = data.getStringExtra("photo");

        Glide.with(VisitorDetailActivity.this).load(selImage).into(iDrivingLicense);
    }
    else if(requestCode == 97 && resultCode == RESULT_OK)
    {
        barCode = data.getStringExtra("barCode");
    }
}

在此处输入图像描述

4

2 回答 2

1

首先,您需要从该方法中全局获取视图checkIn对象

View view;
view = dialog.getCustomView();
final EditText etPassNo = (EditText) view.findViewById(R.id.etPassNo);

现在在你的onActivityResult方法下,我可以看到你已经在那里得到了条形码,所以只需再次启动 EditText 对象,只需在其中设置数据即可。

barCode = data.getStringExtra("barCode");
EditText etPassNo = (EditText) view.findViewById(R.id.etPassNo); 
etPassNo.setText(barCode);

让我知道这是否有效。

于 2019-12-12T10:20:55.840 回答
1

你可以使用界面来完成

public interface OnBarcodeSelect{
    void onBarcodeSelected(String barcode);}
OnBarcodeSelect onBarcodeSelect;
private void checkin()
{
    final MaterialDialog dialog = new MaterialDialog.Builder(VisitorDetailActivity.this)
            .customView(R.layout.sample,false)
            .build();

    View view = dialog.getCustomView();
    final EditText etPassNo = (EditText) view.findViewById(R.id.etPassNo);
    final EditText etVehicleNo = (EditText) view.findViewById(R.id.etVehicleNo);
    final ImageView ivScanCode = (ImageView) view.findViewById(R.id.ivScanCode);
    final TextView tvCancel = (TextView) view.findViewById(R.id.tvCancel);
    final TextView tvSubmit = (TextView) view.findViewById(R.id.tvSubmit);

    etVehicleNo.setText(model.getFldVehicleNo());

    if(barCode != null)
    {
        etPassNo.setText(barCode);
    }

    ivScanCode.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            //Toast.makeText(VisitorDetailActivity.this, "Bar code scanner", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(VisitorDetailActivity.this, ScanCodeActivity.class);
            onBarcodeSelect = new OnBarcodeSelect() {
                @Override
                public void onBarcodeSelected(String barcode) {
                    //handle barcode here
                    etPassNo.setText(barcode);
                }
            }
            startActivityForResult(i,97);
        }
    });

    tvCancel.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            dialog.dismiss();
        }
    });

    tvSubmit.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            if(etPassNo.getText().toString().trim().isEmpty())
            {
                Toast.makeText(VisitorDetailActivity.this, "Pass No is required", Toast.LENGTH_SHORT).show();
                return;
            }
            if(selImage == null)
            {
                proceedCheckin(etPassNo.getText().toString(), etVehicleNo.getText().toString());
            }
            else
            {
                proceedCheckinImage(etPassNo.getText().toString(), etVehicleNo.getText().toString());
            }
        }
    });

    dialog.show();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == 98 && resultCode == RESULT_OK)
    {
        selImage = data.getStringExtra("photo");

        Glide.with(VisitorDetailActivity.this).load(selImage).into(iDrivingLicense);

    }
    else if (requestCode == 99 && resultCode == RESULT_OK)
    {
        selImage = data.getStringExtra("photo");

        Glide.with(VisitorDetailActivity.this).load(selImage).into(iDrivingLicense);
    }
    else if(requestCode == 97 && resultCode == RESULT_OK)
    {
        barCode = data.getStringExtra("barCode");
        if(onBarcodeSelect != null){
            onBarcodeSelect.onBarcodeSelected(barCode);
        }
    }
}
于 2019-12-12T10:29:39.363 回答