从dialogfragment更新微调器

时间:2014-02-05 17:02:52

标签: android android-dialogfragment

我的班级 TelaEntrada.java 正常加载 Spinner

        public class TelaEntrada extends Fragment {
            public Fragment newInstance(Context context) {
                TelaEntrada telaEntrada = new TelaEntrada();
                return telaEntrada;
            }

            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View root = inflater.inflate(R.layout.telaentrada, container, false);
            DbEntrada banco = new DbEntrada(getActivity().getApplicationContext()); 
            List<Tipo> tipos = banco.todosTipos();
            List<String> item = new ArrayList<String>();
            for(Tipo tipo : tipos){
            item.add(tipo.getDescricao().toString());
        }
        final Spinner spn_Entrada = (Spinner) root.findViewById(R.id.spnEntradaTipo);
        ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(
                this.getActivity(),
                android.R.layout.simple_spinner_dropdown_item, item);
        spn_Entrada.setAdapter(adapter2);

我在另一个类中也有一个DialogFragment。代码如下。

public class DialogTipo extends DialogFragment    {
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        final View root = (View) inflater.inflate(R.layout.dialog_tipo, container, false);
        final EditText txtDialogTipo = (EditText)root.findViewById(R.id.txtDialogTipo);
        Button btnDialogTipoAdd = (Button) root.findViewById(R.id.btnDialogTipoAdd);
        Button btnDialogTipoCancel = (Button) root.findViewById(R.id.btnDialogTipoCancel);
        btnDialogTipoAdd.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DbEntrada banco = new DbEntrada(getActivity().getApplicationContext());
                banco.insereTipo(txtDialogTipo.getText().toString());                           

                //I want update my spinner here!

                dismiss();
            }
        });

        getDialog().setTitle("Inserir Novo Tipo");
        return root;
    }
}

我想添加一个新项,微调器直接更新数据库以在User微调器中显示新信息。谢谢。抱歉我的英文!

0 个答案:

没有答案