我想在我的Android应用程序中使用自定义对话框,所以我创建了一个扩展DialogFragment的类,我在Fragment类中使用它,但是它没有工作。
我的自定义对话框类:
public class MyDialogue extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.my_dialog, null);
}
}
//my_dialog.xml has the layout of dialog
enterData(View view)方法设置在espensecashfragment.xml中按钮的onClick属性 有我的片段,我的对话框应该显示在其中:
//This is where I want to use the dialog
public class ExpenseCashFragment extends Fragment implements AdapterView.OnItemSelectedListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.expensecashfragment, container, false);
return view;
}
public void enterData(View view){
FragmentManager manager = getFragmentManager();
MyDialogue myDialogue = new MyDialogue();
myDialogue.show(manager, "MyDialogue");
}
}
有一部分espensecashfragment.xml,按钮链接到enterData方法:
<Button
android:id="@+id/enterButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativeLayout"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Enter"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginBottom ="100dp"
android:onClick="enterData" />