Open Macj opened 10 years ago
Can you clarify what you mean by 'calendar functionality'? Do you mean the DatePickerDialog?
Yes, I mean the DatePickerDialog.
After i add
(:import (java.util Calendar)
(android.app DatePickerDialog DatePickerDialog$OnDateSetListener)
(android.app DialogFragment)))
and
(declare date-picker) (declare show-picker)
(defn date-picker [activity](proxy [DialogFragment DatePickerDialog$OnDateSetListener] [] %28onCreateDialog [savedInstanceState] %28let [c %28Calendar/getInstance%29 year %28.get c Calendar/YEAR%29 month %28.get c Calendar/MONTH%29 day %28.get c Calendar/DAY_OF_MONTH%29] %28DatePickerDialog. activity this year month day%29%29%29 %28onDateSet [view year month day] %28on-ui %28.setText %28::date %28.getTag mylayout%29%29 %28str year %28format "%02d" %28inc month)) (format "%02d" day)))))))
(defn show-picker [activity dp](. dp show %28. activity getFragmentManager%29))
My app ends with the error after loading part and wright before starts.
My code looks like yours:
(ns org.stuff.events.main (:use [neko.activity :only [defactivity set-content-view!]] [neko.threading :only [on-ui]] [neko.ui :only [make-ui]] [neko.application :only [defapplication]] [clojure.string :only [join]]) (:import (java.util Calendar) (android.view View) (android.app Activity) (android.app DatePickerDialog DatePickerDialog$OnDateSetListener) (android.app DialogFragment)))
(declare android.widget.LinearLayout mylayout) (declare add-event) (declare date-picker) (declare show-picker)
(defn mt-listing [](atom %28sorted-map%29)) (def listing (mt-listing))
(defn format-events [events](->> %28map %28fn [[location event]] %28format "%s - %sn" location event)) events) (join " ")))
(defn format-listing [lst](->> %28map %28fn [[date events]] %28format "%s - %s" date %28format-events events))) lst) join))
(defn main-layout [activity] [:linear-layout {:orientation :vertical, :id-holder :true, :def `mylayout} [:edit-text {:hint "Event name", :id ::name}] [:edit-text {:hint "Event location", :id ::location}] [:linear-layout {:orientation :horizontal} [:text-view {:hint "Event date", :id ::date}] [:button {:text "...", :on-click (fn [](show-picker activity %28date-picker activity%29))}]] [:button {:text "+ Event", :on-click (fn [](add-event))}] [:text-view {:text (format-listing @listing), :id ::listing}]])
(defn get-elmt [elmt](str %28.getText %28elmt %28.getTag mylayout%29%29%29))
(defn set-elmt [elmt s](on-ui %28.setText %28elmt %28.getTag mylayout%29%29 s%29))
(defn update-ui [](set-elmt ::listing %28format-listing @listing%29) (set-elmt ::location "") (set-elmt ::name "") (set-elmt ::date ""))
(defn add-event [](let [date-key %28try %28read-string %28get-elmt ::date%29%29 %28catch RuntimeException e))] (when (number? date-key) (swap! listing update-in [date-key](fnil conj []) [(get-elmt ::location) (get-elmt ::name)]) (update-ui))))
(defactivity org.stuff.events.MyActivity :def a :on-create (fn [this bundle](on-ui %28set-content-view! this %28make-ui %28main-layout this%29%29%29) (on-ui (set-elmt ::listing @listing))))
(defn date-picker [activity](proxy [DialogFragment DatePickerDialog$OnDateSetListener] [] %28onCreateDialog [savedInstanceState] %28let [c %28Calendar/getInstance%29 year %28.get c Calendar/YEAR%29 month %28.get c Calendar/MONTH%29 day %28.get c Calendar/DAY_OF_MONTH%29] %28DatePickerDialog. activity this year month day%29%29%29 %28onDateSet [view year month day] %28on-ui %28.setText %28::date %28.getTag mylayout%29%29 %28str year %28format "%02d" %28inc month)) (format "%02d" day)))))))
(defn show-picker [activity dp](. dp show %28. activity getFragmentManager%29))
can you help my?
9 ÍÁÑ 2014, × 20:47, Kris Calabio notifications@github.com ÎÁÐÉÓÁÌ(Á):
the DatePickerDialog
Do the versions of the software stack match mine? If you're using newest version, they may cause problems. I know, my tutorial may be out of date. I haven't checked if my code works with the latest versions, but I will do so when I find the time. Until then, maybe you can post the output from adb logcat
Macj, I finally found the time to update my tutorial. It works with the newest stable versions at least on my machine. I made a one breaking change, namely the listing atom no longer calls a constructor.
I'm not exactly sure what caused your problem, but a running app crashing and losing your REPL is not too uncommon due to the fragility of current tools. If your code looks exactly like mine, try running lein droid doall
at the command line to rebuild the app and re-establish the REPL connection. Let me know if that fixes it.
Hi! When I add a calendar functionality, my app start to dies. When I click on a Event date button app shut down.