constructing a increment value and decrements - android

how can I do the the gui in the picture, like the increment value and decrements, first I thought that there are three buttons one on the top of other but,maybe there is something else. Here is a pic of it

Maybe you are looking for the NumberPicker?
NumberPicker is the basic UI element (+ button, plus a number editor, plus a - button) that is used to build up the DatePicker and TimePicker.

Related

Is there any way to make long texts in android have a behaviour like the photo below (Read more button)?

is There any way in android to make some lines of the long text loose color ?
I'm giving you all the hints which you need to come up with solution rather than writing a solution
I'm assuming that your text is dynamic in nature that means text length will vary.
First of all, you will have a constant defined in your class which provides max line count to show initially (along with read more) button
// here for example, you want to show 5 lines along with read more button
private static final int DEFAULT_DESCRIPTION_LINES_PORTRAIT = 5;
Now, as soon as you set your text, you check whether your text's line count is less than 5 or not. If it's less than 5 then you don't need to show read more button at all. If it's more than 5 then you would set maxLines of that TextView to your default lines. Also you'll make read more button visible
textView.setMaxLines(DEFAULT_DESCRIPTION_LINES_PORTRAIT);
readMorebutton.setVisibility(View.VISIBLE);
Now, you'll simply toggle maxLines to either default or actual line count whenever user presses on that button. Along with that make readMoreButton visibility gone to visible respectively.
Also it might be possible that TextView layout inflation takes time, so you might want to run a runnable on post of that TextView so that you're sure whenever you call textivew..getLineCount(); then you'll get correct value.
Regarding that gradient on top of button, you may simply have that button along with full width view on top of it (which would have a gradient background) in a vertical LinearLayout.
I hope this helps.

Is there a performence difference between creating a button programmatically or creating it in xml?

I want to create 16 buttons each have different texts on it.Those text will be picked up randomly from an array depending on another random value.Lets say,
I have 3 words (apple,banana,watermelon), when the activity created it will pick up one of these words.Lets say apple.And in this activity's screen there will be 16 buttons.These buttons must have the letters that apple consists of "a","p","p","l","e" and the remaining buttons will be filled up with other remaining letters of the alphabet.
So in my case what I wonder is should i do the button creation programmatically by taking a value and assigning this value on creation one by one or do it in the xml and leave their text parts and fill up programmatically.
These 2 options in detail :
First : I'm going to create a function which takes a String value as a paramater and returns a button with this text set on it by using setText(); and then locate it in the layout.
Second : I create the layout with those button and leave blank their text parts and in the activity I only assign their letter values.
I vote for the second option but I'd like to know what's your opinion and would there be a difference in terms of performance or memory ?
The disadvantage of declarative approach is that you can get only so
far with XML.
XML is great for look and feel of your user interface, but it does not provide a great way of handling user input. That's where the programmatic approach came.
Everything you can do declarative as well as with programmatically. But java also allows you to specify what happens when the button is actually clicked.
This is the main advantage of programmatic approach to the user interface.
So what is Best ?
Here it is , Both are good at thier point.
1) Use XML , when everything about your user interface is static , such as layout of the screen , all the widget etc.
2) Then switch to the programmatic approach when user interacts with various widget in the user interface.
In other words you would use XML for what the button Looks like and
Java to specify what it does.

Can EditText jump to next position (timer)?

My timer app (see picture below) seems like a EditText field where i can set numbers (from right to left). After setting one number it jumps to the one left to it (or if it is its end, it replaced the first number on the right). It also have leading zeros.
So i want to create something like this too, but not with a fixed amount of numbers. Is this possible with a editText or should i use TextView or another element? I tried to use EditText because on focussing it can open a Numpad (i don't want a fixed Numpad).

Android Application - On Screen Keyboard Input Method

I am trying to build an on screen keyboard, for a simple counter application, that adds some points for 2 diffeent teams in 2 columns.
The design thing is pretty simple, but it seems hard for me to programm the buttons, in order to insert numbers properly.
I have added all the necesery OnClickListeners and used for example this code for number 1
editText1.setText("1");
But, when i try to press the 1 button multiple times, it doesn't type 111 etc. It keeps replacing the last number that was inputed. So if i press 1 and then 2, it just replaces 1 with 2.
Any idea on how this can work please? :D
setText sets the text. It doesn't append the text. If you want to append, use editText1.setText(editText1.getText()+"1");

adapting time picker in android to individual needs

I need to get alarm start/end time from the user and would like to use the time picker dialog. However I checked the tutorial and I don't understand what I have to do to adapt it to my needs - like for instance in the alarm on Android with different TextViews and buttons.
I have not found a tutorial that shows how to adapt the time picker - could you please provide a link or an example on how to adapt the time picker.
CLARIFICATION:
All I need is the dialog that allows the user to provide hour and minute in the way the time picker does - everything else I would like to adapt. Eg add another TextView which changes value, depending on the hour + minute the user just selected (without pressing OK). I do not want the AM/PM field.
Or is it simply the best to just put two individualized number pickers or number sliders (if this exists) next to each other ? Then I need to handle all details like range etc myself! Possibly there is a sample for this somewhere?
Many thanks

Categories

Resources