在Android

时间:2017-12-20 20:16:27

标签: android android-alertdialog

我在Activity中以编程方式创建对话框。该对话框具有自定义视图,该视图也是以编程方式创建的。此自定义视图包括TextView和ImageView。默认情况下,将显示TextView并隐藏ImageView。单击TextView时,我调用Intent从图库或Camera中选择一张照片。选择照片后,我希望隐藏TextView,并使用此选择的照片显示ImageView。

那我怎么能这样做?

dialog.setTitle("Complete task informations");
                        // The container layout inside of the dialog
                        LinearLayout layout = new LinearLayout(context);
                        layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(pickIcon);
                        // The chosen icon
                        CircleImageView pickedIconDia = new CircleImageView(MyActivity.this);
                        pickedIconDia.setVisibility(View.GONE);
                        layout.addView(pickedIcon);
                        // The listener to click event on both icon (to change) and its chooser (to pick)
                        View.OnClickListener pickIconListener = new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                pickIcon(pickedIconDia);
                                if(taskIconPath != null){
                                    pickIcon.setVisibility(View.GONE);
                                    pickedIcon.setVisibility(View.VISIBLE);
                                }
                            }
                        };
                        // Releying the listener to the two widgets
                        pickIcon.setOnClickListener(pickIconListener);
                        pickedIcon.setOnClickListener(pickIconListener)

我不知道如何从onActivityResult将照片设置为ImageView。 我知道有些活动管理可以收听此类活动,但我找不到合适的活动。

我尝试了Eventbus,但它没有用。

那么,这怎么可能?

附加代码

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) {
                // Get the Image from data

                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                // Get the cursor
                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                // Move to first row
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                //
                Picasso.with(this).load(taskIconPath).into(myView);
            }
        } catch (Exception e) {
            Toast.makeText(this, getString(R.string.some_error_occured), Toast.LENGTH_LONG).show();
        }
    }

0 个答案:

没有答案