How can i store a value from text view and set it at Specific event ؟

OmarMohOmarMoh USMember ✭✭

Hi all

I want to store a value from text view and , the text view show the value and it well change , and I well use if condition with some events , if the event equals for example 0 set the value you store it , for example the value I store it from text view is 10,5 , use if condition and when the condition equals for example zero the text view displayed 10,5 . I hope my problem is clear and I hope someone can help me :(
thanks for all

Best Answer

Answers

  • PubuduGayanPubuduGayan NZMember ✭✭✭

    @omar.7226 can you post your code snipes what you tried so far?

  • OmarMohOmarMoh USMember ✭✭

    @PubuduGayan
    first I'm working with time picker and timer together and I want to store the time I selected and start timer , when the time equals 00:00:00 I want to set the time I selected before etc..

    here my code

    Main Activity.cs ;-

    Timer _timer; int _countsecond = 1; TextView textview; int seconds = 59; int minutes; int hours; string _t; Button _btnpick; Button _start;
    `textview = FindViewById(Resource.Id.tvTimeCount);
    _btnpick = FindViewById(Resource.Id.pickTime);
    _start = FindViewById(Resource.Id.startcount);
    _start.Click += delegate
    {
    _timer = new Timer();
    _timer.Interval = 1000;
    _timer.Elapsed += _timer_Elapsed;
    _timer.Enabled = true;
    _timer.Start();
    };
    _btnpick.Click += delegate
    {
    TimePickerDialog _tp = new TimePickerDialog(this, TimePickerCallback, hours, minutes, true);
    _tp.Show();
    };

            hours = DateTime.Now.Hour;
            minutes = DateTime.Now.Minute;`
    

    private void _timer_Elapsed(object sender, ElapsedEventArgs e) { CountDownTimer(); }

    private void UpdateTime() { _t = string.Format("{0}:{1}:{2}", hours, minutes, seconds.ToString().PadLeft(2, '0')); textview.Text = _t; }

    ` private void TimePickerCallback(object sender, TimePickerDialog.TimeSetEventArgs e)
    {
    hours = e.HourOfDay;
    minutes = e.Minute;
    UpdateTime();

        }`
    

    `private void CountDownTimer()
    {
    if (seconds != 0)
    {
    RunOnUiThread(() => {seconds--;

                    UpdateTime();
                });
    
            }
            else if (seconds == 0 && minutes != 0)
            {
                RunOnUiThread(() => {minutes = minutes -= 1;
                    seconds = 60;
                    _countsecond--;
                    UpdateTime();
                });
    
            }
            else if (seconds == 0 && minutes == 0 && hours != 0)
            {
                RunOnUiThread(() =>
            {
                    hours = hours -= 1;
                minutes = 59;
                seconds = 60;
                _countsecond--;
                    UpdateTime();
            });
            }
            else if(seconds == 0 && minutes == 0 && hours == 0)
            {
                RunOnUiThread(() =>
                {
                    Toast.MakeText(this, "hello", ToastLength.Short).Show();
                    UpdateTime();
                    textview1.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) =>
                    {
                        textview.Text = e.Text.ToString();
                    };
                });
            }
    

    `

  • OmarMohOmarMoh USMember ✭✭
    edited August 2016

    i'm sorry in CountDownTimer() the last condition I put textview1.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) =>
    {
    textview.Text = e.Text.ToString();
    };
    it just was try to copy the textview in another textview but field and I removed :)

Sign In or Register to comment.