I am trying to change line count and TextSize in my text view on SmartEyeglass dynamically. I am calling showLayout() in my ControlExtension to show the layout on the glasses and then sendText() when my text changes. But I don't know how I can send layout instructions like setTextSize for example. or auto calling setMovementMethod() on the TextView to auto scroll down.
My only idea for those dynamic layout changes would be to create the whole layout in my ControlExtension, edit and render it there and send it as bitmap to the glasses as it changes . But they state in their documentation you shouldn't do it in the new API (4) and use the layout functions instead (showlayout and sendText)
Has anybody found a way to send dynamic layout information to the glasses?
Your idea is the right way to go. To change the text size or position dynamically you will need to create your layout in code and then call showBitmap() to redraw the layout each time.
Related
in my Android App I show the user some messages. Therfore I have Linearlayouts which contain a textview. Whenever the App receives a new message I add a LinearLayout to my page, set the LinearLayout's background to a custom one and then add the TextView to it in code. What I want to do is to create a custom View, which is basically the LinearLayout with a custom background and the textview in it. And/or a View which displays all the messages by itself.
What I want to achieve is that I only have to add one view to my XML-Layoutfile. In my code I then simply add all the messages to a property of the view and those messages are displayed automatically.
I hope you understand what I want to achieve.
Thank you for your help!
It sound like Andre Classen said a RecyclerView is maybe the best way for your. You can create custom layouts for different Cards, Rows, and display them.
Here you find more about the Recycler View with Official Tutorial.
I have a .xml file(picture below). In my .xml, the second row's views create while running.
I want my new created views get the same properties from the existing views, like textsize, maxlenght, text-alighn , etc
I tried to change the things that I set for first row views in xml, but some of my codes don't work. for example, this line:
b2.setTextSize(b.getTextSize());
doesn't change the TextSize of the second Button.
what can I do?
enter image description here
Edit:
Is there a function that could be able to get the whole attributes together and set them for new views?
I'm fooling around with Android and trying to make a simple application to split a bill between friends.
I'm wondering if there is a way to create buttons and textfields based on user input. For example, if the user says he needs to split the bill 5 ways, how can I generate 5 buttons and 5 textfields? Similarly, splitting 10 ways will create 10 buttons and 10 text fields.
Thanks,
Ben
Edit: I should mention I have implemented the input already. I simply need to use the input to generate the buttons and textfields.
What you need is to create a Linear layout that have only a button and textfield then you can dynamically add that layout into your activity main's layout programatically. You can follow this thread on how to add view dynamically to another view
I've had a similar problem. You need to make a custom layout and then use LayoutInflater to "put it into another layout".You can use the return of inflater.inflate() to get the parent layout. then you just use parent.getChildAt(i) in a for loop for all "fields" and getChildAt(whatever the index of the button or text field you want is) to get the buttons and access them programatically. You can also give every Button a unique ID with setId(generateViewId(yourButton)) to access them from other functions.
I have a standard layout and i have to populate it at runtime with a number of controls/views i.e. TextView / EditText depending on the number of products that come back from a REST service.
Of course the control I wish to add to the layout at runtime needs to contain a number of views (textview, edittext) etc. I was thinking a custom control to bring all the controls I need I am unsure.
The other idea I had was to inflate and existing XML into my layout but I am unsure if this is possible or if it was or would I control the ID names - inserting more than 1 would cause duplicate id's?
I will try and explain in detail what I am trying to do, we can wrap it in a for loop for test which would count form 1 to 5 hence 5 controls would get populated on my layout.
The custom controls would have a TextView which describes the product. The Edit text where the user can enter freely the amount in numbers using the virtual keyboard and a spinner control to the right of the EditText which would allow the increasing of the EdtiText value.
So all pretty simple eh ? :-) but of could I class all these controls as 1 specific view and I need to a number of them on my layout hence if there were 5 products there would be 5 custom controls, each custom control contain controls i.e. TextView, EditText and Spinner.
How can I accomplish this?
The examples I have seen have been inheriting from VIEW but I need my VIEW (CUSTOM CONTROL) to be a container for a number of other controls and then later be able to dynamically add this new custom control onto my Activity Layout.
What about using a ListView with custom adapter...
check http://www.ezzylearning.com/tutorial.aspx?tid=1763429
http://www.framentos.com/en/android-tutorial/2012/07/16/listview-in-android-using-custom-listadapter-and-viewcache/
You may want to use a ListView with a custom Adapter, and update the adapter with the information from the service.
I want to create a pocket reference application. So, much of the content would be texts, linkbuttons and images.
I wonder where is a good place to put all of the contents. I could place it hard-coded on the source code, So, when a user click a linkbutton, a new view will be opened and in the source code I specify the TextView and setText, etc. But I think it's not a good idea. Can I put the content in an xml file or in a database? Which one is better for this case?
I see that we are encouraged to put layout in main.xml. But, from what I read, the xml layout is static, what if I want to put some TextView, but I don't know how many TextView would be displayed, because the content would be loaded dynamically/programmatically?
Thank you.
Not sure it this is what you meant:
You can initialize your application ui by an android xml file layout.
to inflate, you use this method.
in your activity's onCreate()-Method or even later, you can then get the TextViews or whatever you want by calling findViewById(R.id.textview). Note that this method will search all over the layout xml file for the specified id and though blocks the ui thread while searching. if your textview is very near at bottom and many other elements come before it, this can take some time.
if you want to build your own layout dynamically, you have to do this programmatically of course.
for general layout declaring, refer this tutorial on android dev guide.
You could write the textView in a xml layout and inflate it dynamically in the activity as many times you want
View view = getLayoutInflater().inflate(R.layout.scroll_project, null);
//then add the view in linear layout as
layout.add(view);