【发布时间】:2015-03-08 21:43:25
【问题描述】:
我正在尝试在片段类中实现对话片段。基本上我已经在片段类中的一个按钮上设置了一个动作监听器,该按钮将打开一个对话框,用户将在其中输入两个 EdiText 字段然后按确定,它将将该用户输入传递给 SQLite 数据库。
我该如何实现呢?我需要充气什么?我是使用 Fragment 的新手
ublic class tsk extends Fragment {
DatabaseHelper help;
Button add;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_notes, container, false);
add = (Button) view.findViewById(R.id.addbtn);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getActivity(), "onClick works", Toast.LENGTH_SHORT).show();
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
//LayoutInflater inflater= getActivity().getLayoutInflater();
//this is what I did to added the layout to the alert dialog
final EditText titleInput=(EditText)layout.findViewById(R.id.dialog_title);
final EditText bodyInput=(EditText)layout.findViewById(R.id.dialog_body);
}
});
return view;
}
【问题讨论】:
标签: android android-activity android-fragments android-dialogfragment