0

I have some activities displaying the current date and time. I want to make only one text view (layout) txtTime showing time and it will be updated each second by a handler in main activity. Then others views of other activities can re-use the text view txtTime by including. (I want only 1 handler updating date/time value and all app activities can display this value)

In fact, I don't know how to create/access a text view like that txtTime. As usual I find a text view by (Activity).findViewById(R.id...). But since it does not belongs to any activity I got stuck there.

My pb: How to use a TextView as an application circle object which doesn't belongs to any activity? How to change its text value(Date or Time)?

Do you have any suggestion/solution for me? Thanks,

@ The reponse of Remy: You want something like that : static final TextView appTimeText = new TextView(appContext);, And in the handler appTimeText.setText("Text"); Now when you create the latout in any activity simple add it. – Remy

Anh-Tuan Mai
  • 1,129
  • 19
  • 36

2 Answers2

0

Tell me if I understand you currectly, you dont want to make your textview inside an any activity, because you want to use it in all the life circle of the application? So if im understand you currect you want the application context. Then you can retrievegetResources()

Im hope im understand you properly.

Community
  • 1
  • 1
Remy
  • 1,053
  • 1
  • 19
  • 25
  • Since I use: getApplicationContext().getResources().getLayout(R.layout.current_date) It returns a XmlResourceParser and I don't know how to do with that. How to change text value of TextView "current_date"? My layout "current_date.xml": Thanks for your help. – Anh-Tuan Mai Jun 19 '15 at 07:16
  • @Anh-TuanMai I FINNALY UNDERSTAND YOU! XD, You want something like that : `static final TextView appTimeText = new TextView(appContext);`, And in the handler `appTimeText.setText("Text");` Now when you create the latout in any activity simple add it. – Remy Jun 19 '15 at 14:48
0

If you want other activities to get the text view from the 'txtTime' layout then <include @layout/txtTime' /> in the other layout.

codeFreak
  • 353
  • 1
  • 3
  • 15