I'm trying to make a app with some nice features. One of them is :
I want to modify the text that you see in my app on user request. By this I mean if you see the MENU name in my app and want to display it as MAIN MENU or MY MENU etc you press a button, open an edit interface, write the name,click ok and that's it, text changed.
Here is little part of my aplication, it's shows up Slide to change the brightness, but user want to change it to “Brighness changer” . Any ideeas how to do that ?
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Slide to change the brightness"
android:id="#+id/textView"
I know that all my names are saved in a strings.xml file , problems is that i don't want to recompile my app everytime user will make a change..that's the main problem. I need a way to do it to avoid this .
Thanks in advance !
You store the string they want to use in a shared preference. When you display this layout, read the value from the shared preference and call setText on the TextView to set the text. Use the existing string as the default, of course.
Related
I am just starting with android. This is what i want to make:
Now when you click on From, a new screen would open where you can select places and once you select you will get back to this screen where instead of "Bangalore" it would be the place you selected.
What kind of a field is this ? Text field ?
Also if i want to add any effect like when you click on it its color changes, how would i go about it ? Any tutorials or documentation i can check out for this.
Yes, you will probably want to use TextView.
You can change the text it displays by using SetText(), and you can change the text color by using SetTextColor().
You need a TextView to display text, but if you want to display an image, text and be able to interact with that, then Button or ImageButton is what you need.
Your question is too broad, so I encourage you to start doing some tutorials. To implement all that stuff you'll need to learn about layouts and activities, dialogs, listviews, ... Basic Android, but it needs a minimum of experience.
Is there any shortcut for editing properties of a widget in Android Layout editor in ADT?
I need to change gravity of TextView lots of times, but every time I have to use mouse...
You could do a search and replace on a particular string in the layout.
Highlight only the TextViews you want the search to happen in
Search > Search
Enter the string to be replaced and press the "Replace" button or "Replace
All" button.
If you post the exact xml listing of your layout, I can be more exact in which string needs to be replaced. If that solution doesn't work for your particular case, to save some time, I suppose you might also be able to create a particular custom Eclipse template for your TextView.
A third option would be to use inheritance and create a customTextView with the gravity already set a certain way.
And a fourth option still would be to set the properties of your TextViews programmatically after the fact using both XML and Java (instead of only using XML).
Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.
First things, first, I'm just starting with Android Application Development and would like to make a basic starter app. I have a Hello World app which will display the text Hello World when a button is pressed, but I would like to know how I can include a text box for a name, so the user can enter their name and then have the app say hello to them when they press the button.
Any help would be appriciated because I haven't a clue if I'm honest, I'm still figuring out what most of the code does but creating simple apps like this help me further my understanding.
Thank you,
Max
For the text box you'll probably want to use a EditText. Make sure to insert it into your layout xml and give it a name you can reference, like nameTextBox or something. It should look something like
<EditText android:layout_height="wrap_content" android:id="#+id/nameTextBox" android:layout_width="match_parent"></EditText>
Then when your activity runs, make sure to put it into a variable like you probably did your HelloButton. So
setContentView(R.layout.layout);
nameBox = (EditText) findViewById(R.id.nameTextBox);
Then when the user clicks the button go ahead and grab whatever is in the nameBox. If you're using a ClickListener for your button this would go inside the OnClick method, just before you print out the text.
String name = nameBox.getText().toString(); // Inherits toString from CharSequence
// code to display concatenate and display your hello string goes here
I advise you to look at the samples provided by google on the android developer page.
http://developer.android.com/resources/browser.html?tag=sample
Look how things are done there and use that to make your own
I am working on an application that asks the user for specific settings at the start. For example, my first activity asks the user:
Use option?
-option A
-option B
Now, after the user selects what option he/she will use I would like to be able to change the resources my app uses. I am specifically talking about the values/strings.xml where I have different strings for different options of the application.
For now, I am using option A as the default one and I put all the strings in the default strings.xml file and for now option B shares the same strings, however I am expecting option B to need a few specific strings that I will need to define in another file, but cannot figure out a way to decide what is the best approach to do this?
Thanks in advance
EDIT:
To answer jkhouw1's question, option B will only change existing strings. If I was to use string arrays as resources, how would I be able to specify this in my layout.xml file and then be configured by what the user chose on the first activity? - to translate this in an example:
If I have a TextView I want to define its text in the layout.xml like <TextView android:text="#string/(key)" />
If I was to use string arrays for the not common strings, how could I define the android:text attribute for my View in the layout.xml file depending on what option the user selects?
Thanks
Unfortunately, there doesn't seem to be a way to do what I am trying above currently.