0

I'm developing an app which will prompt a user a DatePickerDialog, after the user insert the date i'll manage the date and add it to a listview. So far i have achieved:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_somministrazione);

    Button Aggiungi;
    ListView ListaSomminisrazione;

    Aggiungi = (Button) findViewById(R.id.button3);
    ListaSomminisrazione = (ListView)findViewById(R.id.listView2);

    final ArrayList<String> ris = new ArrayList<String>();

    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(Somministrazione.this,android.R.layout.simple_list_item_1 , ris);

final Database db=new Database(getApplicationContext());

    Aggiungi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            showDatePickerDialog();

         //WAIT FOR THE DIALOG TO DISMISS IN ORDER TO ADD THE GIVEN DATE CHOSEN BY THE USER INTO THE ListView ListaSomminisrazione;

    }
    });

public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
    int year2,month2,day2;
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
         int year = c.get(Calendar.YEAR);
         int month = c.get(Calendar.MONTH);
         int day = c.get(Calendar.DAY_OF_MONTH);

        // Create a new instance of DatePickerDialog and return it
        return new DatePickerDialog(getActivity(), this, year, month, day);
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {

        // Do something with the date chosen by the user
        year2 = year;
        month2 = month +1;
        day2 = day;


      //HERE I WANT TO ADD THE VARIABLES year2,month2,day2 AFTER BEING SET BY THE PREVIOUD METHOD IN THE LIST VIEW

    }

}

public void showDatePickerDialog() {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(Somministrazione.this.getFragmentManager(), "datePicker");

}

}

I apologize for my language, English isn't my main course. Any kind of help would be appreciated ( i'm a newbie tho )

For the database part i have written in a file called Database.java this method:

    public void InserisciSomministrazione(String data, String quantita, Integer Id_Farmaco){
    ContentValues cv=new ContentValues();
    cv.put(Somministrazione.DATA, data);
    cv.put(Somministrazione.QUANTITA, quantita);
    cv.put(Somministrazione.ID_FARMACO, Id_Farmaco);
    DB.insert(Somministrazione.TABELLA_SOMMINISTRAZIONE, null, cv);

}
Vesco
  • 138
  • 2
  • 15
  • please add more details and be more specific about your query. – Sufiyan Ghori Dec 24 '14 at 13:13
  • I think it's pretty clear.. - After clicking a button a DatePickerDialog will be prompted - Adding the retrived data into a ListView I do also use a Database in this app, but in this case it's pretty irrelevant, don't you think ? – Vesco Dec 24 '14 at 13:19
  • where is your listView model class or adapter ? – Murtaza Khursheed Hussain Dec 24 '14 at 13:20
  • @user2551165 you are sound confusing tho .... retrieved data and picking a date these are two different things.... – Umair Dec 24 '14 at 13:20
  • added the adatper for the list. for retrieving date i mean getting the date that the user will insert through the DatePickerDialog. And then add what the user inserted to a ListView. – Vesco Dec 24 '14 at 13:25
  • @user2551165 ok what I understood is that you want to fetch the date entered by the user and save it in database and then insert it to listview. OR you just want the user to pick the date and that date will be shown in listview ? – Umair Dec 24 '14 at 13:27
  • You are missing a call ListaSomminisrazione.setAdapter(arrayAdapter); – Bhavik Mehta Dec 24 '14 at 13:57
  • @Darkie You got it. It would be perfect to add it to the database ( i have alredy edited my first piece of code to include it ) and then showing it in the ListView – Vesco Dec 24 '14 at 14:40

0 Answers0