2

I doing simple stopwatch.

I have StopwatchActivity.java

I have ListAdapter but i need set custom font.

How to do it? I was looking for examples, but I can not find the with "String"

It works.

Code: http://pastebin.com/zgA0f0jq

To moderators: I have error when I need paste code here "Your post does not have much context to explain the code sections; please explain your scenario more clearly."

user1704195
  • 179
  • 1
  • 4
  • 16

2 Answers2

0

Check this sample here

you need to inflate it so that you can set the text with the font you need to have. I can suggest you to use a baseadapter so that you can get the textview and set the typeface to it

G_S
  • 7,068
  • 2
  • 21
  • 51
  • It's my BaseAdapter. http://pastebin.com/Qvzq3tu3 i Have error in line m_lapList.clear(); – user1704195 Sep 27 '12 at 18:06
  • The method clear() is undefined for the type StopwatchActivity.MyAdapter – user1704195 Sep 27 '12 at 18:08
  • public void onResetClicked(View v) { Log.d(TAG, "reset button clicked"); m_stopwatchService.reset(); m_lapList.clear(); } If i have normal ListAdapter it work. – user1704195 Sep 27 '12 at 18:15
  • you have used setListAdapter(new ArrayAdapter(this, R.layout.laps_row)); in your code and its saying The method clear() is undefined for the type StopwatchActivity.MyAdapter ?? – G_S Sep 27 '12 at 18:15
  • I using it like this: setListAdapter(new MyAdapter(this, new ArrayList())); m_lapList = (MyAdapter)getListAdapter(); – user1704195 Sep 27 '12 at 18:16
  • well try creating an object myadapter = new MyAdapter(this, new ArrayList() and call myadapter.clear(); – G_S Sep 27 '12 at 18:18
  • I have it: setListAdapter(new MyAdapter(this, new ArrayList())); – user1704195 Sep 27 '12 at 18:22
  • instead am asking you to once check well try creating an object myadapter = new MyAdapter(this, new ArrayList() and call myadapter.clear(); – G_S Sep 27 '12 at 18:22
  • It doesn't work. I think that problem is here : private MyAdapter m_lapList; before it was private ArrayAdapter m_lapList; – user1704195 Sep 27 '12 at 18:25
  • Why did you use ArrayList() ? Is that a seperate class? or you are trying to use the Object of java.lang? – G_S Sep 27 '12 at 18:30
  • No I do not use. How else to write? – user1704195 Sep 27 '12 at 18:34
  • then what is Object? over there? – G_S Sep 27 '12 at 18:35
  • For constructor: public MyAdapter (Context context, List objects) { this.context = context; this.objects = objects; } – user1704195 Sep 27 '12 at 18:40
  • What does that List contain ? – G_S Sep 27 '12 at 18:41
  • Gets Item (int position) BaseAdapter took from the example. – user1704195 Sep 27 '12 at 18:44
  • Well i suggest you to change Objects to String itself. It should solve your problem – G_S Sep 27 '12 at 18:47
  • It doesn't work. of course works but error remained. – user1704195 Sep 27 '12 at 18:52
  • The method clear() is undefined for the type StopwatchActivity.MyAdapter – user1704195 Sep 27 '12 at 18:56
  • not just that some thing like this the screen capture at the end of the question in http://stackoverflow.com/questions/12190242/adwhril-sample-example-giving-classnotfound-exception – G_S Sep 27 '12 at 19:01
  • I created methods for. Clear () and insert () and there is no error But the program breaks where I shall write. – user1704195 Sep 27 '12 at 19:02
  • where did you write them? I am not able to find the clear and insert methods in the links – G_S Sep 27 '12 at 19:06
  • I wrote just now public void insert(String formattedElapsedTime, int i) { // TODO Auto-generated method stub m_lapList.insert(m_stopwatchService.getFormattedElapsedTime(), 0); } public void clear() { // TODO Auto-generated method stub m_lapList.clear(); } – user1704195 Sep 27 '12 at 19:07
  • then just call m_laplist.clear(); No need to write a method for that. hey what object is m_laplist ? – G_S Sep 27 '12 at 19:13
  • But when I called m_laplist.clear() i have error that undefined method. mlapList is private MyAdapter m_lapList; It's for new lap. – user1704195 Sep 27 '12 at 19:15
  • there is something that i am missing..... well is it a private app that should not be revealed ? If its not so try to post the entire code. I will try to check the problem with it – G_S Sep 27 '12 at 19:19
  • sharathg.satya@yahoo.co.in I would do it the next day as it is midnight here and even i am not sure that i will come with a solution as it has something different classes and so which i need to refer . So please Dont mind and give the sample if you can – G_S Sep 27 '12 at 19:25
0

You can set font to each TextView in your xml, like so:

<TextView 
android:id="@+id/button2"
android:layout_height="wrap_content" 
android:layout_width="wrap_content"
android:typeface="sans" />
WSBT
  • 33,033
  • 18
  • 128
  • 133