Showing an internal log in an Android app - android

I want to show an internal log inside an activity. This log consists of text strings that inform the user about the status of an operation.
For example:
Process started
Doing task A
Doing task B
...
Process stopped
The only way that comes to my mind is to use a ScrollView with a TextView that will be updated whenever there is a new string in the log, but this solution seems inelegant.
Is there any UI widget that serves as a container for lines of text?
EDIT: I prefer not to use a ListView, I just want to show lines of plain text in a container, something simpler
EDIT 2: I used to develop Win32 programs in Delphi. There we have a TMemo component that serves as a container for lines of text. I'm looking for something similar in Android

What's inelegant about updating a TextView? This is the most straightforward and simplest way to implement what you're looking for.
A TextView updated by a background polling event, probably by way of an Thread/AsyncTask is what I would try first. Don't confuse necessary complexity with inelegance. Sometimes the obvious first idea you have is the correct one.

Why not use a vertical linear layout instead a ScrollView. Then just add TextViews to the LinearLayout as they are received. This would be more elegant that just appending the text items.

Related

Dynamically change the content/layout/flow controlled via server

I am new to android development, and we have a very specific requirement.
We need to change the content/layout/flow of the app on the fly. For e.g. we have a layout which consists of some images, textarea and textboxes. There might be a request coming to change the textarea to a textbox.
We thought about this and are thinking to provide the apk with a json/xml which will contain all these changes.
My question is will it be possible to re-draw the objects again dynamically and change the content?
Yes this is possible. You can dynamically design what has to be displayed in your Activity UI screen. If you feel there are only 2 or 3 different UI screens that would be repeatedly used, then you can have XMLs for these screens and you can just change their labels in OnCreate() of Activity class before rendering. LayoutInflater class would be helpful here.
When you design a Android Application with Activities and Fragments your XML layout definition is always static. If you want a true dynamic layout structure you should use a Web View with a HTML content pointing some URL.
As Rahul says, another approach is to manage the "default cases". For me that is the standard way to design an Android Application.
The dynamic content (values) can be done with a simple http call to server you can get values for your views.
The navigation could be handled by switching Intents, but, definitively you have to associate these intents to UI elements like buttons in the most cases, and ¿How you can do that if your layout is changing over time?.
I think, that the WebView could be a very easy solution for your problem.

DISABLE the auto arrange of widgets in eclipse

I'm fairly new to android programming (making the switch from Windows programming to Mobile Platforms.)
Problem: Every time I add, let's say, a text view, I get a green box around it that will put it in a location. When I add multiple text views, I go to place it down under another text view and everything in my app shifts, and moves everything into a stack on the upper left most part of the screen. It seems like every time I move one thing, 5 other things move with it.
Question: Is there a way to disable that function?
Go to your layout, right click it, then click on change layout. I changed it to absolute layout so I can move any or my widgets around the screen as much as I wanted without the movement effecting other widgets. Hope this helps
Android forces you to develop without a pixel-rigid notation. Basicly you have a set of Layout types (Linear, Relative, etc) that stablish a relation between the child's elements.
Therefore, it is important to know those Layouts, how can you connect them and how their childs are arranged.
In eclipse you can add elements but some things eclipse doesn't know how they are related. Eclipse will update the new data, and therefore moving all kind of views out of the way to update into the new hierarquy you defined. Therefore you can't remove "auto-layout". Even if you change to Absolute Layout (like David suggested) you are not removing the "auto-layout" feature. You are simply telling eclipse that you want to arrange your things with absolute positioning. However, absolute positioning is not advisable since you have several devices with different resolutions.
I advice you to read some information about Layouts and then try to use the XML. Don't be afraid. It can become quite easly. Actually, I prefer XML to interface builder in eclipse. After you get some idea how layouts work you can use make a better use of the interface builder.

Appcelerator: Proper Way Automatically Dismiss Keyboard

I'm writing an app using Titanium. I want to be able to automatically dismiss the keyboard anytime something outside of the text field is clicked. I have yet to find an elegant solution for this issue.
Couple things that I've thought about, but am still looking for a better solution:
Assign event listeners to basically everything else present in the view, and dismiss the keyboard (using textField.blur()). I want to avoid this since it results in a LOT of code just to dismiss the keyboard. Also, if I end up adding anything else to the view, I'll have to add a click listener to that object as well, so it's not very maintainable.
Create a large transparent view, and have it take up the entire screen. Place it directly beneath the text field and add to it one click listener on that which will dismiss the keyboard. This is a better solution than #1, but still isn't great because I've had a lot of trouble getting zIndexes to work properly. It's also inefficient for my purposes because I've got views with a specific width and height that encapsulate text fields. I've used these for the sake of code simplicity and I re-use them throughout my application.
I've tried adding a listener for the "blur" event for the text field but that doesn't seem to get fired appropriately.
That's about it. I'm sort of at a loss. The zIndexing also behaves strangely on the iPhone, and I haven't tried on Android yet. Also, as I mentioned above, many of the text fields I use are encapsulated within small views with set widths/heights-- so I think that will affect the functionality of Z-indexes.
So the root question is: What's the best way to dismiss a keyboard whenever anything outside the text field that's in focus is clicked?
If I'm correct the click event propagates through all views and windows therefore your #1 option could be modified to check for clicks on the bottom most layer (view or window), check for its source then decide what to do.

Problems with android GridView

I am trying to display 2 columns of text in a GridView in android. I create a TextView for each cell of the grid. Everything seems to work well until the TextView tries to wrap the text to a second (or more) line. When this happens, sometimes the second line of text overwrites the next cell, rather than causing the cell to expand to fit the text. All I have to do to get the text to display properly is click one of the cells in the grid. This seems to cause the grid to repaint and then everything gets displayed properly. I have tried any number of things to fix this problem but nothing seems to help.
Is there some property that I have to set on the TextView or the GridView to allow the cells to expand to fit the text? Or is this just a glitch in GridView that I have to live with?
BTW, setting android:singleLine="true" prevents the word wrap and solves the problem but it isn't an ideal solution because I really don't want the text to be truncated.
At a quick glance, I'm afraid you might have to do a work-around. I know it seems like a glitch, but it may be more ideal to continue to have your views start a consistent location instead of constantly having them shift based on content. I know this is a pain for what you're trying to do, but keep in mind that this was designed for hopefully the best solution for any application. Anyway..
One workaround I would propose might be manually updating the beginning of the views that get written over. I know it's not exactly ideal, but you can figure out where to place it based on the properties of your view. This doesn't feel like a particularly elegant solution though, so I'll try to cook something better up and/or post sample code. Good Luck!

Android - Textview or Drawable generated and animated programmatically

First off, I'm a beginner. If this is way beyond the scope of a beginner's first application, just tell me.
The best way to explain what I want is as an example: In Robo Defense, when you kill something, a little $10 pops up, animate translates/fades up about 5% of the screen and disappears. (almost like a toast, appears on top of canvas)
I'm looking for something similar to that same effect. As a like, top-layer drawable that ignores the underlying defined XML layout. I can handle the animation part of the code, but I'm curious as to how to create and inflate that view without wreaking chaos on my current layout. If it would be easier as a drawable instead of text, thats really not a big problem for my project. It is simply imformative, no interactivity at all, it will just be a quick little 500ms artifact to show that an action has occurred.
I could use a pointer in the right direction, or some similar code examples please.
I think you would create the TextView within your Java code, and then use an animation to make it rise and fade, once the animation has finished, destroy the TextView.
I've never done this before, but I think that should work!
To anyone else who is wondering, I ended up accomplishing this via wrapping my entire layout in RelativeLayout, making the appropriate changes necessary, then creating a TextView programmatically with layout_above, and then calling an Animation on it.

Categories

Resources