Android - how to turn numbers in a TextView into buttons - java

My utility app requires the user to select a meeting from the calendar, then it removes the non-numerical text, and parses what remains using some logic, with the final aim of identifying two numbers only.
Whenever the app fails to remain with 2 numbers only, I want to open a new activity in which the user will "tell" the app which 2 numbers are the relevant ones.
So I want to display the meeting title, location, and description in 3 TextViews but all numbers should be clickable with a special onClick action that will trigger some methods that handle the identified two numbers...
My question is about how to turn the numbers in the textViews to be clickable and have the special onClick action.
I don't think I can use Linkify as I cannot put an onClickListener on the links.
My only idea now is to turn the numbers into clickable buttons and add the relevant listener to the buttons.
1) Any suggestion on how to do this conversion other than simple step by step parsing?
2) Any better idea than using buttons?
Thanks a million

call setOnClickListener(this) on the TextView and supply a onClick method in your code

Related

Is there a way to create pages/activities or something similar based on a users input?

I want to ask a user how many times a week they go to the gym, and depending on their input i want to display "x" amount of activites one after the other.
Example: User inputs 4 days a week. following that, the next activity will be a page for day one, then they click a button, then day 2, then click a button, then day 3 and so on.
One way I thought of doing this is creating 7 activities for the 7 days of the week, but id like to find a better way.
Another way which I'm not sure if its possible, is to create a sort of recursive Activity.
Example: User inputs 4 days a week. following that, the next activity will be a page for day one, then they click a button which opens up the same activity but with all the data they put in previously saved in a DB, and the inputs for day 1 has been cleared, so it becomes day 2.
if any one has any knowledge on the above scenario if you have done something similar or know if android studio has a better way to do this, any input will be appreciated, still a beginner using android studio, Thanks in advance.
Can't you create just different views in Android Studio ? Creating 7 different views would be the easy way, but if you want to do it more elegantly you could create one "template view". So you create a file/view with some placeholders like "Activity" and "Day_X". Then for every page the user can get to, you open up the same view (page, mask) but fill it with different data.
Then you can just based on the user input code something like:
"Create me NUM_DAYS_USER_INPUT times the activity template mask", once with the data for activity one, once with the data for activity too and so on...
You just need to pass the correct data for the single views to the masks.

Which android AdapterView do I need to use if I don't want a list?

This activity has a fixed Toolbar on the bottom and the mid section (rest of the screen) is split in 2 equal parts (LinearLayout with weight 50). This mid section is handled by a fragment. Each sub part has exactly the same views in it. Of course while running the content is different.
On double tap I want BOTH (1 and 2 marked on the picture) to display new content. I do not want to be able to go back on previous Views. I also do not want a list-effect to display new content, I'd like a stacked effect but without CardViews, because you can't remove the space around the cards totally. Also, the next 2 views should appear instantly (I have the data stored locally).
How can I achieve that? Obviously I'm quite new to Android. It seems to me none of the ListView/GridView/StaggeredView does that, although what I need is easier since I basically just want to replace my content using an adapter to avoid recoding.

Update TextView numerous times with Buttons

I am making a simple shopping cart application where the user can select items (via buttons) and their running total will be displayed in a text view.
I am fine with having the text view being updated on a single click but I am struggling to figure out how to write my code if the same button is pressed more than once. For example a button writes a value of £3 into the TextView, if this button was clicked again I want the TextView to increase to £6 and so on.
Further to this I want to be able to have more than value added to the TextView from different buttons. I imagine this is more of a Java question as opposed to Android but seeing as I'm a bit of a newbie to both all advice is welcome!
Into your class if you have price value add an incerementPriceValue and make get/set functions for the last one.
If user press the button
setIncrementValue(getIncrementValue()+priceValue);
setText(getIncrementValue+simbolstring);
Create a int variable count and on the click increase the count value and set that value on the textView

Java ListView class?

What is the difference between a listview layout xml and a Listview Java class? I am trying to make it when a user inputs text and presses enter it comes on a set position on the right but when the user receives a reply it would show up on the left side of the list view. Like text messaging on android phones. Does anyone know how i can do this? With a java class or an xml layout? I want animations and dynamic content on the listview as well. Any ideas?
ListActivity provides you all the built-in features of and methods of ListView but only ListView can be added into the whole Activity. By using ListView in xml, you add multiple Views such as Buttons, EditText on the same Activity.
Basically, the xml is for seperating the design (the visuals) from the code (functionality).
Although you can do some funcationality via xml, it's usually better to do it in Java code in your class.
I guess you can create a ListView that will iterate through 2 different list enteries:
The first will show the data (the text in your case) on left and the second entry will show on the right. For each list entery you will create a different xml layout with widgets aligned to the left and right as needed.

Android, show dialog when ListPreference item is clicked

Basically I have a ListPreference to allow a user to change the X position of some text on my Live Wallpaper.
It contains 4 entries: top, middle, bottom and manually input X. The first 3 options are no problem, I simply get the SharedPreferences in my WallpaperService class and check if they are top, middle or bottom and change the position corresponding to their choice.
However, the last option is proving more difficult, what I want to do is have an EditText alert box popup when the user clicks the "Manually input X" ListPreference item so they can enter a value for X. I just cant figure out how to make the alert popup from clicking that specific List element.
You probably want to create a custom ListPreference. Basically you want to extend from ListPreference (see original here), and provide a custom protected void onPrepareDialogBuilder(Builder builder), in which you provide the additional "custom" list item and the onclick to handle the selection of the "custom" entry.
Note that I keep saying "custom" because it would be a best practice to make this class as reusable as possible.
Override onPreferenceTreeClick() in your PreferenceActivity and compare the preference it gives to the one you want to do something for.

Categories