Android - Something Odd... Question - android

Something odd is going on, I think...
I have menu with sub-menu items.
One sub-menu gets GPS location, does some calc's and updates two display fields. No problems.
The other sub-menu takes user input and does calc's BUT, it uses the same display stuff as the fist sub-menu but, won't update the two fields with the new input for display. I have a second display just to see whats going on and this display does update the two fields correctly.
There are no differences between these displays (declarations, parameters or values) HOWEVER, and here's the lead-up to the odd thing, I got a warning when setting the display for the two fields (for displaying in the second sub-menu) and used a suggestion from the pop-up.
The suggestion was to make the TextView static. I clicked it for one (left the other as-is for trial and commented it). The warning went away but, crash! at run time.
So, here's the odd thing: Nowhere do I see anything that makes this TextView static! All related declarations and ref's to it are identical to the one I didn't make static. In fact, I tried to manually make the second one static but couldn't. I also checked the R.java file but nothing related in there...
Fortunately, I was able to use 'Undo' the Make-it-static.
Any comment/clarification for my education?
Thanks

The "Make it Static" suggestion only applies to your Java code. If you check out the declaration of your TextView it will now say something like static TextView mTextView. As for the other problem, there is no way to say for sure what is going on without seeing your code.

Related

How to debug list view problems?

I have a list view with some complex layouts.
Some parts of the layouts are set visible/adjusted at runtime (i.e. not everything set by the xml).
It has caught my attention than in some "rare" cases there is a specific part (the same in all cases) that is rendered visually either a few seconds after looking at the list item or if I scroll down the list and then scoll back up again.
What I observe is that it seems like after a few seconds the list item is "redrawn" and the item suddenly appears.
I have added debug output to check for its visibility and according to the console log, the item is visible when the getView is called for that the first time.
So I have no idea what the issue might be.
How can I debug issues like this?
There is an option in the developer pane on your cellphone that flash every time a piece of screen change.
You can also use something like this https://github.com/JakeWharton/scalpel
If you are using an android device you can activate 'developer options' (you'll have to google how to do this for your device as it varies) like Luca said. These are really cool because you can see where changes appear on the screen and add layout borders etc which make it easier to see exactly what is happening. They can be really useful for debugging sometimes!
I had a similar problem and I tried removing most of my code and adding chunks back in to make sure they were working and eventually you should be able to locate at least the general area where the problem is.
Good luck! Sometimes these things can take a while!

Android drag & drop

Before that I start explaining the problem I need to say one thing: I'm totally new to android programming, I can use java without problem, but i still don't know the android packages and classes.
I have a LinearLayout with 2 columns, inside the first column there are some buttons, the second contains a scrollView, in this scrollViewthere should be some... items that the user can add, those items have a title and a text, i already defined thoose objects in another class, and i add them to the scrollViewfrom a button.
From now i put in that object a button that is used to delete the item, but now i realized that it's really ugly, so i was thinking: is it possible to allow the user to drag and drop the item out of the screen to delete it?
I could surely do it by managing the event of pression and release on the item with some listener, but i'm almost sure that there's some android class created for sliding UI components.
Something like what you do with android notification.
I post an image of how the current app is so you can understand better what i said: http://i.stack.imgur.com/fHWK3.jpg (I don't have enough reputation to post images)
If i wasn't clear just say and i will edit with the requested information.
UPDATE: After reading the resource that Bonatti posted in his answer i added a OnLongClickListener for starting the drop, and a OnDragListener to look the cordinates during the drag, now i have a problem... I need my component to be dragged only horizzontally like how you usually remove notification from the notification bar, i thought about the fact that i could save the Y-location of the shadow created by the DragShadownBuilder when i create it, and then i could check in the OnDrag event if the Y-location now is different from the beginning i correct it, but the problem is... how can i access the shadow's location?
The basics of what you are asking for can be found here:
I cant post more than 2 links, so redo these:
http:// developer.android.com/guide/topics/ui/ drag-drop.html
These other might help with what you need in details:
Link 1: code.tutplus Or Link 2: vogella
They both answer what you need.
To put it simple:
You need an "action" to receive that a button/something was pressed (and that is still being pressed), and then update the screen to match the item position

How to find the code related to a small UI component quickly in a large Android codebase?

I just started my work as an Android developer. My first assignment is to fix several bugs of an App call DailyFinance.
One bug is UI related, if you click a button on a certain page, a dialog will pop up, but the dialog is not displayed properly. My question is how can I locate the code (xml layout file as well as activities) related to the dialog quickly in the codebase which I am not familiar with?
Couple approaches come in mind:
Search for any text that displayed on the target dialog.
Search button text and locate the xml layout file that that contains the button which launch the target dialog
Once find the xml layout file, determine the button 'id' as xxxxx, then you can further search for source contains references to 'R.id.xxxxx'
Set breakpoints on methods in files that implement the dialog. So maybe search for dialog and then put breakpoints inside the dialog. See it it gets hit when your dialog gets pulled up. Or just see where the layouts are set in files that have the word dialog in them. look for R.layout.someLayoutName.
One other suggestion is for some difficult layouts where its tough to see whats going on you can use the HierachyViewer to see the runtime view layouts: http://developer.android.com/tools/help/hierarchy-viewer.html Its worth running on your app to see the structure of the layouts at runtime which is often hard to see these relationships in the layout files before they have been inflated.
BTW, I was a student of CS and the biggest mistake I ever made was not to learn the debugger inside and out. Its without a doubt the most powerful ally you have to learn as well as fix bugs. If you think about it, code really is only an abstraction until you see it running inside the debugger.

ListView SectionIndexer's box is transparent

In my app I'm using a listview with a section indexer that displays the letter of the current selection. It's fine on a lot of devices, but when I use my app on a Galaxy Tab running Android 3.2 the letter is displayed without the little box. I don't know how to make it appear or change the color of this letter.
I tried to use android:textColorPrimary but I didn't find how to use it and I find no sample.
To see my problem, below is a screenshot. If you look carefully, the letter G is in white above the second element of the list.
This is kind of a strange answer, because I fixed it, but I'm not sure why. When I set FastScrollEnable = true later than in the contructor of my derived ListView I get this behaviour aswell. Although, my letter is almost completly off the screen.
I'll probably get downvotes for this answer, but it saved me after 6 hours of prodding around. I noticed it when I removed my prototype code from our main classes to change the FastScrollEnable from outside.

Component to add arbitrary number of input fields?

I apologize if I'm just missing the obvious. I'm fairly new to Android development, and while I searched for this particular topic, I wasn't exactly sure what to look for (in terms of a "name").
In an application I'm writing, I have a section where the user can enter the names of players. However, this can range anywhere from 1 to whatever, no limit. However, I'm not sure what the best approach for this kind of feature is, or if there's a component that already does something like it.
Basically, the functionality I'm looking for is similar to what you can see in the Edit Contact screen of the phone book; for the phone numbers and email addresses, you can push a little plus button to add a new number/address, or hit the little minus button to remove a number/address.
I can think of several ways to potentially implement this, but in the end I think wrapping it in a custom component would be best (so that you could call "Get Players" and have it return a list of strings by going through each of the inputs and getting the values).
Am I just overthinking this? Is there a component that does that already? Is there some example code that demonstrates a good way to do this?
Thanks!
Could you just use ListView and add a menu with a "Add Players" option? You could customize the list view to have a little checkbox, for example, and then begin the game by pressing the menu ... or add new players dynamically by pressing another menu button.
After playing around with some ideas, I came across a solution that I think will suit what I'm doing. I created a custom component extending LinearLayout. As part of the creation of the component, it creates a row that says "Add new..." with a plus-sign button. Pressing the plus sign button then creates a new row containing an EditText and a minus-button which will remove the row.
I then created a method for this component called getTexts() which returns a List that has all the non-empty Text values from all the components. Testing it in a dummy app, it seemed to work fine.
I think I need to make tweaks to make it more robust (like the ability to add rows programatically, listeners to alert other components when a row is added/removed, and the ability to set the individual EditText values, for instance), but this functions as I imagined.

Categories

Resources