I’m trying to set the text of a TextView in a layout using ViewPager. This is the code I have:
setContentView(R.layout.main);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.Panel);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
String text;
if (Math.floor(hours) <= 12)
text= hourFormat.format((Math.floor(hours)));
else
text= hourFormat.format((Math.floor(hours) - 12));
Typeface FontType = Typeface.createFromAsset(this.getAssets(),"fonts/TIMES_SQ_0.TTF");
View sResource = getLayoutInflater().inflate(R.layout.setup, null);
Method = (TextView) sResource.findViewById(R.id.Method);
Method.setTypeface(FontType);
Method.setTextSize(20);
Method.setText(text);
The ViewPager works fine, setting the font and size don’t work. Setting the text does not work either. I don’t know why setText doesn’t work. Also, that text is dynamic so I can’t use a resource string to set it.
To clarify: hours is the hour of the day.
Well in this piece of code you initialize
textbut never assign any value to it.Do something like:
Or if you assign it elsewhere, just remove
String text;