1

我正在编写View负责捕获图片并进行预览的文章。我正在使用 实现它Fragment,只要我需要使用startActivityForResult().

它做了我想要的,但在捕获后我需要Image在我的中得到它,CustomImageView class我的问题是我无法FragmentView我的Custom View.

这是代码:

自定义图像视图:

public class CustomImageView extends LinearLayout {
  private LayoutInflater inflater;
  private View view;
  private CustomFragment frag;

  public CustomImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initViews();
  }

  private void initViews(){
    inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.view_imageview, this, true);

    //  Get Fragment Here . . . .
  }

}

view_imageView (CustomImageView xml):

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/fragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        class="com.example.fragments.CustomFragment"
        custom:viewParameter="eg ari ra"
        tools:ignore="MissingPrefix" />

</LinearLayout>

所以我需要进去FragmentinitViews()正如我上面评论的那样),但我不知道怎么做。请分享您的想法。

如果可以,请你帮助我。提前致谢

4

1 回答 1

0

你试过......以下:

首先尝试获取 FragmentManager

FragmentManager manager = ((Activity context).getFragmentManager(); 或 ((FragmentActivity) context).getSupportFragmentManager();

片段片段 = manager.getFragmentById("fragment");

于 2014-01-23T13:46:47.863 回答