Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextView defStyle parameter ignored?

Note that I am using Mono for Android

I have a ListView of items that can be extended by clicking a "More" button at the bottom of the list. The list is defined in XML but the more button is simply a clickable TextView that is added to the bottom of the list via AddFooterView. I am trying to apply a pre-defined style to the runtime-created TextView but it is not working.

mMoreProductsButton = new TextView(this, null, Resource.Style.more_button);
mMoreProductsButton.Text = "More";
mMoreProductsButton.Click += new EventHandler(MoreProductsButton_Click);
mListView.AddFooterView(mMoreProductsButton);

TextView documentation shows this signature: TextView(Context context, AttributeSet attrs, int defStyle)

defStyle is defined in the documentation as the default style to apply to the view. An example I saw elsewhere passed null as the AttributeSet but I'm not sure if that is valid or related to my problem.

I found this bug and am not sure if it is related and current: http://code.google.com/p/android/issues/detail?id=12683

Any suggestions are appreciated!

like image 959
profexorgeek Avatar asked Nov 13 '22 15:11

profexorgeek


1 Answers

I also searched answer to this question. It seems to be an Android bug because I didn't found a way of style applying to creating Views. Why don't you want to inflate your TextView?
Like this:

layout/my_view.xml

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:style="@style/more_button" />

Activity

TextView mMoreProductsButton = (TextView) getLayoutInflater().inflate(R.layout.my_view, null, false);

Sorry, I don't know if it workable in Mono.

like image 64
nostra13 Avatar answered Dec 20 '22 17:12

nostra13