Ankit HTech
Ankit HTech

Reputation: 1893

How to refresh a view component run time in android

I want to change the text of Text view pragmatically in my android application, here is my code to set the string to the text view

TextView dateTime;
dateTime = (TextView) findViewById(R.tasksheetlist.txtdatetime);

    private void updateDateValue(String date)
    {
        String text = dateTime.getText().toString();
        text = text+"\n"+date;
        dateTime.setText(text);
    }

and this is how the function called some where

            Date date = new Date();
            String dateStr = Helper.ConvertDateStringFromDate(date, "DD MMM");
            updateDateValue(dateStr);

This code called but does not reflected on the view.

I think I need to refresh the layout but do not know how?

Please help me in this??

Upvotes: 0

Views: 364

Answers (1)

Bhavesh Patadiya
Bhavesh Patadiya

Reputation: 25830

I think this article will help you. http://android-developers.blogspot.com/2007/11/stitch-in-time.html Basically you want to use the Handler class provided in the SDK. You shouldn't need to call invalidate like because setText does that for you. Hope this helps!

Upvotes: 1

Related Questions