Android Tutorial PreferenceActivity tutorial

David S

Member
Licensed User
Longtime User

Actually Google's documentation sucks big time....

Dim x As Int = ett.INPUT_TYPE_NUMBERS
Dim y As Int = ett.INPUT_TYPE_DECIMAL_NUMBERS

x = 2
y = 12,029​

So now that I know the Google Android documentation is so untrustworthy, as apparently Erel is also aware of, if you need the value of the input type (as in AddEditText2 - post # 155) then you have to pull it from the view.

Seems a shame you have to add the overhead of creating a edittext view just to get a parameter because Google may change it's value in the future.

But hey, if they are calling these objects "Views" instead of "Controls" then you have to be on your toes. lol
 

ivanthomson

Member
Licensed User
Longtime User
Thanks for the tutorial Erel.

Is there any example of adding a secondary preference screen to the first screen and then adding items to the secondary and actually opening it when the user clicks on the item in the first screen that leads to the second?

For example;

If I have a preference screen built up and I enter this line of code;

cat3.AddPreferenceScreen(PFsecondaryscreen)

How do I add items to PFsecondaryscreen and how do I open it?

Your tutorial mentions being able to do this, but unfortunately, it doesn't show how. I've tried things but I can't seem to figure it out.

Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use this sub (based on the tutorial code):
B4X:
Sub CreatePreferenceScreen
   screen.Initialize("Settings", "")
   'create two categories
   Dim cat1, cat2 As PreferenceCategory
   cat1.Initialize("Category 1")
   cat1.AddCheckBox("check1", "Checkbox1", "This is Checkbox1", True)
   cat1.AddCheckBox("check2", "Checkbox2", "This is Checkbox2", False)
   cat1.AddEditText("edit1", "EditText1", "This is EditText1", "")
   
   cat2.Initialize("Category 2")
   cat2.AddList("list1", "List1", "This is List1", "", _
  Array As String("Black", "Red", "Green", "Blue"))
     
   'add the categories to the main screen
   screen.AddPreferenceCategory(cat1)
   screen.AddPreferenceCategory(cat2)
   Dim screen2 As PreferenceScreen
   screen2.Initialize("screen2", "screen2 summary")
   Dim s2cat1 As PreferenceCategory
   s2cat1.Initialize("Category on 2nd screen")
   s2cat1.AddEditText("edit2", "EditText2", "This is EditText2", "")
   screen2.AddPreferenceCategory(s2cat1)
   screen.AddPreferenceScreen(screen2)
End Sub
 

ivanthomson

Member
Licensed User
Longtime User


Thanks, again, Erel. I much appreciate the help and the tutorials. You do a fantastic job!
 

khosrwb

Active Member
Licensed User
Longtime User
hi
how can I start new activity by this library?
I need to use webview in app.
 

khosrwb

Active Member
Licensed User
Longtime User
I will open new activity by click on item.
B4X:
startActivity(MyActivity)
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
I will open new activity by click on item.
You want to open a new activity from the PreferenceActivity ? If yes, you should take a look at AHPreferenceActivity which extends this one
 

khosrwb

Active Member
Licensed User
Longtime User
You want to open a new activity from the PreferenceActivity ? If yes, you should take a look at AHPreferenceActivity which extends this one
yes I will too .
if possible write code for me.
I read AhpreferenceActivity library , but I don't know .
B4X:
StartActivity(main2)

thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
if possible write code for me.
Hello,
Please find a modified example attached.
The call to the Activity named "main2" is done via an intent and registred in the Manifest. So don't forget to replace the package's name by your own in your own app.
 

Attachments

  • main2.zip
    8.1 KB · Views: 493

khosrwb

Active Member
Licensed User
Longtime User
Hello,
Please find a modified example attached.
The call to the Activity named "main2" is done via an intent and registred in the Manifest. So don't forget to replace the package's name by your own in your own app.

thanks lemonisdead
your help was usefull for me.
 

palmzac

Active Member
Licensed User
Longtime User
Hi Erel,

OIC. Thank for your help !


 

jairbj

Member
Licensed User
Longtime User
Hi friends, does it is possible to add an ActionBar to the top of preference screen with a "back" button?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…