I am creating an Android game and have an issue with dynamic text with a TextView. Essentiall within my layout, I have a TextView, within a Relative Layout with enough space for several lines.
What I would like to do is add 5 lines within the TextView, with a functionality that once it is trying to write a 6th line it automatically overwrites line 1, therefore only ever showing a max of 5 lines of text.
Example of What I am after:
dynamic line 1
...
dynamic line 5
Please find below my xml code:
<RelativeLayout android:id="#+id/battleconsole"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:gravity="center_horizontal"
android:layout_below="#+id/spacer1" >
<TextView
android:id="#+id/battle_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Console with information" />
</RelativeLayout>
This is the code that I am using to update the text within the TextView:
TextView update = (TextView)findViewById(R.id.battle_details);
update.setText("test console data going in here");
I am not sure if this is even possible using a TextView, if not is there any other way I can solve this issue?
Thanks in advance
Keep the 5 lines in a collection (array or list). When you set the text on the TextView, join the lines in the collection on "\n". Then just replace the item in the collection with the updated text.
Android has a join method in the TextUtils class, but I prefer the Guava library's Joiner class. Check it out: Google Guava
Related
I don't know what to say to this but I want mask or put patch on Text view.
See the picture below. I want effect like this. I've searched lot but didn't find any post with same requirement. How to achieve this?
You can pass two images in one TextView Like below Code:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/icon"
android:drawableRight="#drawable/pacth_icon"
/>
use
android:drawableLeft
and
android:drawableRight
to set your images in TextView.And you can setText and background Image as well.
I'm a beginner devoloper. I'have a problem with Spinner in my xml file.
The spinner is this:
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/spinnerA"
android:gravity="center"
android:text="Symbol A"
android:entries="#array/teamList"/>
There is too much black space between the end of text and the down arrow of spinner. As you can see, the word "Atalanta" is truncated in Atala.., but there is a lot of blank space on the right. How can I solve?
Thank you for helping me
Replace -
android:layout_width="match_parent"
android:layout_height="match_parent"
with -
android:layout_width="wrap_content"
android:layout_height="wrap_content"
and when you see the output in any device , you will see the proper output.
There is a listPreferredItemPaddingEnd in the default layout simple_list_item_1.
So you can use your own spinner adapter with your own layout item.
You need to create an arrayAdapter, override the getView method and return your own item view.
I solved, adding android.paddingRight=0dp to the Spinner. In this way, there is more free space and the word "Atalanta" is not truncated in Atala..
I have a standard straight forward EditText, I want to show the dictionary suggestions on top of this EditText so I did this in the XML:
<EditText
android:id="#+id/messaging_messageEdit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_weight="85"
android:background="#drawable/clanz_edit_text_holo_dark"
android:ems="10"
android:hint="Type your message here..."
android:singleLine="true"
android:inputType="textAutoComplete"
android:textColor="#dedede" >
</EditText>
I thought that the inputType parameter would take care of the auto dictionary view. On my phone (Nexus Android 5.1) the dictionary view appears but is blank. On a Genymotion emulator (Android 4.1.1) it does not display at all.
What am I missing?
This can be one solutions if you are looking for AutoComplete TextView.
<AutoCompleteTextView
android:id="#+id/from_station"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/enter_start"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:textColorHint="#color/transparent_black" />
You can also set threshold value using paramters.
Need to set adapter values at runtime.
If I understand correctly you want the keyboard to have auto correction right?
According to the Android developers website:
Can be combined with text and its variations to specify that this
field will be doing its own auto-completion and talking with the input
method appropriately. Corresponds to TYPE_TEXT_FLAG_AUTO_COMPLETE.
This is not what you're looking for. You are probably looking for textAutoCorrect which is this according to the Android developers website:
Can be combined with text and its variations to request
auto-correction of text being input. Corresponds to
TYPE_TEXT_FLAG_AUTO_CORRECT.
I've made a lot of apps and never used one of those though. It just auto corrects if you have a normal EditText.
I had the same problem not getting keyboard suggestions on some of my EditText views. Please pay attention there is a difference between autoComplete text views and getting keyboard suggestions while typing! They happen in two different places, first one inside the AutoCompleteTextView the other one on top of your keyboard while typing.. (for example you type te => it suggests "tea teaspoon teapot" to make your life easier.)
To achieve that I had to turn off the input types that I was setting programmatically and when you do so, the default behavior is back and that means getting keyboard word suggestions:
// etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
I tried the following but I still did not get a keyboard suggestions:
etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
at the end I commented all the above and it worked just fine!
here I also found that someone else had the reverse problem meaning they wanted to disable this functionality and they suggested to use the code that I had commented! read here
i am developing an app, i would have linked an image but i don't have enough reputation to do so....my problem is The text doesn't fit in one line it goes to the second line,obviously thats because i have set the height to "wrap_content",but i want it to show the text only in one line and not 2 or more,what should i change the height to?i don't want any java code for this,my fragment is already heavy with lots of code,is there any way to do this on xml, so that it doesn't display different results for different screen size?also is there any way i can append "..." to the end of the name? like "backupRestoreConf..." or something like that?
use android:maxLines="1" (or android:singleLine="true", but it was deprecated and now it is not anymore. What to think.)
android:maxLines="1"
Use this in your XML
you need to set this in xml for your textview:
android:singleLine="true"
I am fairly new to java and android. at the moment i am studying java at school. i just started working in this calculator just to get my hand in android developing. my problem at the moment is that when i deploy the app to the emulator (phone size 480x800) looks like Pic 001, but when i deploy it to my Kindle fire 1st gen (1024x600 i believe) looks like Pic 002. how can i make it so it look the same in every phone.
XML File
In order to have your buttons fill the entire width of your screen, put this in your tags Button:
android:layout_width="0dp" android:layout_weight="1"
instead of :
android:layout_width="80dp"
If you want the buttons to be higher :
- In your tags Button change android:layout_height="80dp" to android:layout_height="match_parent".
- In your tags LinearLayout which contain your buttons change android:layout_height="wrap_content" to android:layout_height="0dp" android:layout_weight="1".
- In your tag TextView change android:layout_height="wrap_content" to android:layout_height="0dp" android:layout_weight="X" where X is the value that gives you the right proportions.You will have a warning telling your that nested weight are bad for performance but it's the only way I know to do this.
In general, if you want a component to fill the empty space, set the width or height to 0dp and add a weight. The weight will define the proportions of the elements which want to fill the space.
I hope it will help you.