I'm working on a checkbook app, and I'd like to use a small widget like a TimePickerDialog or DatePickerDialog but one that acts like a keypad so the user can enter an account or transaction balance. I know I can use an EditText but I would like to be able to implement a keypad.
Does Android have any predefined UI elements to support this? I have tried to find some, but without luck. I did find an interesting article to implement my own using a GridLayout, but wondered if someone was aware of any Android classes that could already do this.
The GridLayout method: http://code.tutsplus.com/tutorials/android-user-interface-design-creating-a-numeric-keypad-with-gridlayout--mobile-8677
If you specify android:inputType="numberDecimal" in the XML for your EditText, you'll get a keypad. If you decide that you need a more specialized keyboard, there's a very good tutorial here.
Some tips:
Read this tutorial: Creating an Input Method
Clone this repo: LatinIME
Related
I don't know if this has been asked before. I am going to be building a calculator for my dad. He asked me if there is any way to have customization with the buttons.
I have not done any code yet. I plan on trying a few things. My research has come up with nothing.
This is what I am trying to accomplish, I have a feeling it breaks the android studio law of coding. This is the concept:
Imagine the calculator. You have 8 blank buttons above the numbers. Those buttons ordinarily have the functions such as percent and sqrt.,..etc.
I have been asked if it's possible can he just hold the button and change those functions at will.
So the question at hand is. Can I do if statements to change the symbol and the code for a particular button when long pressed?
The concept of the calculator would be in portrait mode he can customize the buttons to the functions he uses without having to turn the calculator in landscape mode?
So in theory you have a long press which would bring up a selector. He can select any math function and based on that function the symbol and code would change and the button will work properly to the new selection?
I was going to to build the calculator as a standard. But was also wondering myself if this is possible. I know the buttons serve as a one function but in coding anything is possible.
Any help or advice would be appreciated. If this can be done it opens new possibilities to app features to only show what you want and not a predefined controls.
*******once I try a few codes I will edit question to better see the issue and what I am trying to do.
OnLongPress show a dialog with the option you want and change the button text according to selected option.
On Onclick check the button text and call function according to the text
I'm new to android/java and I'm not sure how to solve the following problem:
Basically, I am creating a fitness tracker app and I need to be able to add details about an exercise (a text view and a couple text input fields) to my 'activity_weights_main' when the relevant exercise button is clicked in my 'activity_exercises'page.
At the minute I am trying to call the exercise buttons from 'activity_exercises' in my 'WeightsMain' java class via the code below:
btnCableCrunches = (Button) findViewById(R.id.btnCableCrunches);
After I'm able to call the 'btnCableCrunches' in my 'WeightsMain' java class, I'm planning on creating a method which will add the textviews/input fields that I need. I'm aware this is probably a stupid question but I've been trying to research how to do this for quite a while now with no success.
So I guess my question is: How do I call this button from another activity (activity_exercises) so that I can create a method (in 'WeightsMain.java') to add textviews/input fields (in 'activity_weights_main').
I don't need to know how to create the onClick method, just need to know how to call the button from other activity so I can do so myself. Thanks in advance for any feedback!
Actually you are looking for " Callback Implementation".
You can follow this example for assistance.
I'm creating my first Android App, and as part of it, I need to add new buttons after a click on another button.
Then I need to create() a button after a onClick() event on another button.
How to do it?
Things you should know:
I am using Android Studio to develop the app,
I have already imported these:
import android.view.*;
import android.widget.Button;
import android.widget.TextView;
And I'd like to know where to get the whole Library list for android, or better, I'd like you to say what's your best android library to develop on such these things, I need to find and get experienced on a library so I'll need suggestions!
Thanks a lot in advance :)
P.S. Just typed those create() and onClick() to make it clear that I was talking about methods, but not that both of 'em are real ones or the ones I'll need ;)
P.P.S. I don't know how many buttons will be ther becuase I do NOT choose that, the user does, it's somethig like: I want to create a new thing, then I press the button '+' and create a new button (the new thing), for this reason, the amount of buttons isn't known, that's why I can't use the visibility trick, but yeah I first thought about that aswell!
rockfight's answer is correct, but I would recommend you to use the button in your layout with android:visibility="gone" and then show it when the user taps on the first button using button2.setVisibility(View.Visible).
It's always easier to create your layouts and views in xml instead of code.
Personally, I'm using support-v4 library, recyclerview, recently-released design library and some of the Google Play Services libraries.
EDIT: if you're going to add a lot of buttons, and you don't know how many, I'd recommend you to use ListView or RecyclerView. I personally prefer RecyclerView, but it might be more difficult to set up. Anyway, you'll be adding items to your list. That items are basically buttons, so your item layout would look like this:
item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a new button!"
android:layout_margin="16dp"
android:gravity="center_vertical|center_horizontal"
android:elevation="2dp"
android:translationZ="6dp" />
<!-- Material Design. See http://www.google.com/design/spec/what-is-material/elevation-shadows.html#elevation-shadows-elevation-android- -->
<!-- The attributes you need...... -->
That's all. You don't have to mess with ugly code. If you want to get an idea of the advantages of RecyclerView, see http://antonioleiva.com/recyclerview/.
Create a button object
Button myButton = new Button(this);
Then add button to your layout
LinearLayout layout = (LinearLayout) findViewById(R.id.my_layout);
layout.addView(myButton);
I am not sure what library are you talking about. To learn about android go to android developer website and click search button and search what you want to know. You will get all libraries there.
You do not need libraries for making onClick methods. When you have your button, set onClick method like this: button.setOnClickListener(new onClickListener...) if you press Ctrl+Space you will get possible choices of what to choose.
How many buttons do you wish to add programmatically? Maybe it would be better if you create buttons in xml and use Visibility.GONE and Visibility.VISIBLE if there are not many buttons and you know the end number of them.
My app has an album style feature that users can pick/take photos from device and load it in every page in this album.
Now the number of this album pages is up to user and should be unlimited. On the Other hand the codes that is being used in activities as you could imagine are exactly same. I have wrote code once and I just want to reuse this activity for each page of album. how should I achieve this?
Since there are thousands of apps that are provide this kind of functions I know there is a good way but i'm unable to find that. Just a trick or a link to a tutorial or even a small explanation is good enough.
Thanks in Advance.
You can create a next() method, and change every layout view in the page with this function, so that you are in same activity but only views are being changed.
One solution is to add the data to be displayed to the "extras" of the Intent which you use to start the activity.
Alternatively, you might want to look at using a Fragment instead of an Activity. You might also want to look at using ViewPager to be able to swipe through the fragments which display the album data.
I need some help.
I'm wanting to make an activity similar to this, but I'm not sure where to start.
Basically, it's like a texting UI, with the users question on the right and the answer on the left. I was going to use a list view for the sake of simplicity, but I dont' think it'd support this kind of structure.
I googled some layouts where I can scroll, but most of them require me to premake them, which isnt an option because its a dynamic chat log.
Does anyone here have experience with this kind of UI? Can you point me in any direction? I hate to ask such a strange question, but I don't even know how I'd word this situation on Google.
Thanks in advance.
What you're looking for is a ListView where you can return a different layout depending on whether the message is sent or received. A ListView is the most efficient implementation for this because its ideal for displaying a potentially large data set without having to keep a view in memory for every row.
This is achieved by extending the BaseAdapter in your application and overriding the getItemViewType(), getViewTypeCount(), and getView() methods (along with all the other methods required by a ListView adapter).
This is a good tutorial that serves as a walkthrough for this pattern.
Instead of using ListView, You may programmatically construct a viertical LinearLayout, and add TextView in each line, you can set the alignment of the TextView in lines accordingly.