0

I am working on a Live Project. and we are designing it for 2 languages. So, I have to take each text from strings.xml When I click on any link and when a view is loading it is showing ProgressDialog showing Loading... The code for that is,

ProgressDialog dialog = ProgressDialog.show(HomeScreen_menu.this,"","Loading...", true, false);

but, I want it from from strings.xml

How can I do that?? I tried,

ProgressDialog dialog = ProgressDialog.show(HomeScreen_menu.this,"",R.string.loading_data, true, false);

but, It is showing error at R.string.loading_data because it is int value.

Please Help..!

Thank You..:-)

Java_Android
  • 735
  • 2
  • 9
  • 15

5 Answers5

1

If you are using inside the activity class you can use the below source code.

ProgressDialog.show(HomeScreen_menu.this,"",getResources().getString(R.string.pleaseWait),true,false);

(or)

If you are using normal class, Inside the constructor initialize the activity as parameter then use like below code.

ProgressDialog.show(HomeScreen_menu.this,"",(context).getResources().getString(R.string.pleaseWait),true,false);

Karthik
  • 747
  • 4
  • 21
  • 48
manivannan
  • 622
  • 1
  • 4
  • 17
  • But, if i use this in non-activity file, then it gives an error that create method getResources or getString..whats the solution for it? Your another solution not working..:( – Java_Android Aug 23 '13 at 11:29
  • 3
    you should get the activiy context or application context like as parameter? – manivannan Aug 23 '13 at 11:33
0

Try this:

getString(R.string.loading_data)
Dino Velić
  • 888
  • 11
  • 24
  • But, if i use this in non-activity file, then it gives an error that create method getResources or getString..whats the solution for it? – Java_Android Aug 23 '13 at 11:26
0

like following way.

progressDialog = ProgressDialog.show(HomeScreen_menu.this,"",getResources().getString(R.string.pleaseWait),true,false);

UPDATE: Above solutions is useful from activity class. From non-activity class just need to cast to context like following way

    progressDialog = ProgressDialog.show(HomeScreen_menu.this,"",context.getResources().getString(R.string.pleaseWait),true,false);
Sumant
  • 2,775
  • 2
  • 22
  • 30
0

change this:

ProgressDialog dialog = ProgressDialog.show(HomeScreen_menu.this,"",R.string.loading_data, true, false);

to this:

ProgressDialog dialog = ProgressDialog.show(HomeScreen_menu.this,"",getString(R.string.loading_data), true, false);
Androidparanoid
  • 199
  • 1
  • 9
  • But, if i use this in non-activity file, then it gives an error that create method getResources or getString..whats the solution for it? – Java_Android Aug 23 '13 at 11:30
0

Try this

getString(R.string.loading_data);

FarhaSameer786
  • 370
  • 1
  • 4
  • 12