0

Currently ran into an issue trying to update a list fragment with a dialogfragment input (or dummy input) everything compiles but don't see any change to the list. Please let me know what you think. Thanks.

public class NewEventDialogFragment extends DialogFragment {
    private List<GlobalClass> mItems;
    EditText editText;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        //editText = (EditText) findViewById(R.id.editText);
        builder.setMessage("What Would You Like to Name the Event?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                        mItems = new ArrayList<GlobalClass>();
                        mItems.add(new GlobalClass("Whoiszzzzzzzzzzzzzzthis", "Adsdfdsdomg"));
                        mItems.add(new GlobalClass("Whodsfzzzzzzzzzzzzzsdfsisthis", "Addsdfdfomg"));
                        mItems.add(new GlobalClass("Whoisthzzzzzzzzzzzzzzsdfdsfis", "Addosdfsdfmg"));
                        // Create the adapter to convert the array to views
                        MainTabsPagerAdapter adapter = new MainTabsPagerAdapter(getActivity(), mItems);
                        // Attach the adapter to a ListView

                        adapter.addAll(mItems);

                        adapter.notifyDataSetChanged();
                        //setListAdapter(new MainTabsPagerAdapter(getActivity(), mItems));
                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User cancelled the dialog
                    }
                });
        View view = getActivity().getLayoutInflater().inflate(R.layout.neweventdialog_fragment, null);
        builder.setView(view);

        return builder.create();

    }

}

 private List<GlobalClass> mItems;        // ListView items list

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // initialize the items list
    mItems = new ArrayList<GlobalClass>();
    Resources resources = getResources();

    mItems.add(new GlobalClass("Whoisthis", "Adsdfdsdomg"));
    mItems.add(new GlobalClass("Whodsfsdfsisthis", "Addsdfdfomg"));
    mItems.add(new GlobalClass("Whoisthsdfdsfis", "Addosdfsdfmg"));

    // initialize and set the list adapter
    setListAdapter(new MainTabsPagerAdapter(getActivity(), mItems));
}
  • I don't see the code for this '// Attach the adapter to a ListView ' where is your listview.setAdapter(adapter); – Broak Jul 03 '15 at 16:29
  • ok I added ListView listview = (ListView) findViewById(R.id.list); listview.setAdapter(adapter); but findViewById cant be resolved – Devilishdil24 Jul 03 '15 at 17:29
  • Your listview is still probably called R.android.id.list or something like that, change it to @+id/list – Broak Jul 03 '15 at 17:57

1 Answers1

0
  1. You need to have ListView in your layout R.layout.neweventdialog_fragment and bind this widget to your view in code, then setAdapter on it.

    View view = getActivity().getLayoutInflater().inflate(R.layout.neweventdialog_fragment, null);
    ListView listView = (ListView) view.findViewById(R.id.listView); // you bind to listView your widget
    listView.setAdapter(adapter); // you set adapter
    builder.setView(view);
    
    return builder.create();
    
  2. When you wants to appear DialogFragment, you use NewEventDialogFragment.newInstance().show(getSupportFragmentManager(),CURRENT_FRAGMENT_TAG);

Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51