使用后刷新视图

时间:2017-07-04 18:46:57

标签: java android

单击TextView1在AlertDialog中显示image1 然后单击确定并单击image1上的TextView2 show image2,我尝试在单击TextView2时删除image1但失败... 该怎么办?

image.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/l1"
>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    >

<ImageView
    android:id="@+id/dialog_imageviewd"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/green"
        android:layout_below="@+id/dialog_imageviewd"

        >
<TextView
    android:id="@+id/dialog_textviewd"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:textColor="@color/black"
    android:layout_below="@+id/dialog_imageviewd"
    />
    </LinearLayout>
</RelativeLayout>

PageFragmane.java:

 public PageFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        view2 = inflater.inflate(R.layout.image, container, false);
        textViewd = (TextView)view2.findViewById(R.id.dialog_textviewd);
        imageViewd = (ImageView)view2.findViewById(R.id.dialog_imageviewd);
        return inflater.inflate(R.layout.page_fragment_layout, container, false);
    }

     public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);

     if(length>0)
                {
                    final String imagetxt=images[0];
                    final String t=t[0];

                textView1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        AlertDialog.Builder alertadd = new AlertDialog.Builder(getContext());
                        textViewd.setText(t);
                        int id = getResources().getIdentifier(imagetxt , "drawable", getContext().getPackageName());
                        imageViewd.setBackgroundResource(id);
                        alertadd.setView(view2);
                        alertadd.setNeutralButton("ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface km, int am) {
                            }
                        });
                        if(view2.getParent()!=null) {
                            ((ViewGroup) view2.getParent()).removeView(view2);
                        }
                        alertadd.show();
                    }

                });

            }
        if(length>1)
        {
            final String imagetxt=images[1];
            final String t=t[1];

            textView2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder alertadd = new AlertDialog.Builder(getContext());
                    textViewd.setText(t);
                    int id = getResources().getIdentifier(imagetxt , "drawable", getContext().getPackageName());
                    imageViewd.setImageResource(id);
                    alertadd.setView(view2);
                    alertadd.setNeutralButton("ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface km, int am) {

                        }
                    });
                    if(view2.getParent()!=null) {
                        ((ViewGroup) view2.getParent()).removeView(view2);
                    }

                    alertadd.show();
                }

            });

        }
}

0 个答案:

没有答案