我有一个dialogfragment,当用户点击对话框中的“Ok”时,它被解除,我想重新绘制活动布局。我正在使用viewflipper来处理Activity中设置的三个布局。我是否在片段中使用getActivity()来访问viewflipper?
部分活动文件:
...
private ViewFlipper viewflipper;
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cardviewinput);
viewflipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
部分xml文件:
...
<LinearLayout
android:id="@+id/LinearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/cardview_nobuttons"
android:id="@+id/cardviewNobuttons" />
<include layout="@layout/cardview_previewbuttons"
android:id="@+id/cardviewPreviewbuttons" />
<include layout="@layout/cardview_twobuttons"
android:id="@+id/cardviewTwobuttons" />
</ViewFlipper>
</LinearLayout>
部分片段文件:
...
@Override
public void onClick(View v) {
...
dismiss();
getActivity().viewflipper.setDisplayedChild(viewflipper.indexOfChild
(findViewById(R.id.cardviewNobuttons)));
}
答案 0 :(得分:0)
在活动中为viewflipper创建一个getter,然后将getActivity转换为您的活动类型并访问viewflipper。