Skip to content
Advertisement

In Android Studio why is there no TextViewPreference?

Ok so I wanted to create a Settings activity. I was told using the Preference layout makes it much easier. I want a TextView that when clicked does a certain action, yet there is no TextViewPreference. The closest thing is EditTextPreference that must have the attribute “selectable” set to off which turns it gray.

Also another thing, these Preferences have no ID attribute. How am I supposed to attach OnClickListeners to them if they have no ID???

Advertisement

Answer

try–>

Method 1

create a custom preference layout item and use it in the Preference Activity:-

JavaScript

add in preference xml:

JavaScript

then lastly:-

fire findViewById in your Activity code and attach a listener….

Method 2

For the xml:

JavaScript

Then for the java in your onCreate()

JavaScript

Method 3

You can try it like this to get the Textview in activity:

JavaScript

add android:id to the LinearLayout that contains the Textview in layouttext.xml, i.e. android:id=”@+id/mylayout”

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement