Help coderanch get a
new server
by contributing to the fundraiser

Dov Ezra

+ Follow
since Nov 23, 2010
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dov Ezra

Hello everyone,

I want to code an app that display a set of Items in a list view.
if an item is broken, I want its name to have a strike-thrue line and a red background. for non broken
items, their name will have a blue background and no strike lines.

I tried to use the fallowing code in my ListAdapter.getView() to set the strike line and the background color. the result is that some items have a red background and a line, some with blue bg and line, and some have only blue background.

I don't understand how items can have both strike line and blue background. this method is the only place in my app that set strike line
Here is my code:

13 years ago

I'm writing an app that finding a route from user location to a selected destination.
The general idea is to pick a destination point on the map and user location from GPS or phone tower
and then call Google routing web service.

The question is how should I get user location?
I can call LocationManager.requestLocationUpdates() and start looking for location updates.
but for how long? all I need is one starting point. nothing more. should I stop the listener at the first time
onLocationUpdate() is called? what is the common practice in this situation?

The second option is calling getLastKnownLocation(). how much can I relay on it?
right now I'm using only android emulator. don't have an acctual device to test this app yet.
I tried to connect to the running emulator using telnet and use geo fix to set locations. but then I noticed that calling getLastKnownLocation will not always return the last fix I entered. I'm probably doing something wrong. can you guide me here?

13 years ago
Icon problem solved.
the problem is the way eclipse look for the icon file.
Although I had the icon.png in res/drawable, I didn't have it on res/drawable-hdp,
res/drawable-ldp and res/drawable-mdp. those folders contained only the default green icon.

now its working fine. :-)
13 years ago
I hope you people can share your knowlage about the fallowing questions.

1. I have a Linear Layout with a background image and an ImageView component in it.
is it possible to add a new image that will stand in front of the Image View?

2. I have a Grid Layout containing nine numeric images, each have a white background image behind it:

the problem here is how to scale the white background, but not the image with the number.
I can change the line imageView.setLayoutParams(new GridView.LayoutParams(28, 28));
to something like imageView.setLayoutParams(new GridView.LayoutParams(58, 28));
but this stretch both the number and the white background.
I attach a file with two screen shots. the top one is what I'm trying to achieve and the bottom is what I have now.

3. how do I set an application icon? android documentation says I have to add this line
to my manifest file: <application android:icon="@drawable/icon" >
where drawable/icon refer to a png file named "icon". well, I have that png file, put it in res/drawable
and add that line to the manifest. no result. I don't see my icon but that green default android icon.
what is missing here?

13 years ago
That's one paradigm shift from desktop applications.

if you cannot have modal dialogs that wait for user responce, why would you use dialogs at all?
It may be simpler just to add new activity with yes and on buttons and call it for result.
13 years ago

I don't understand the hang of using Dialogs on android.
after I call, execution don't stop and wait for the user to respond.
it just continue to the next statement. but I need the user to click the yes button before I continue.
that why I need this dialog in the first place.

I know that the AlertDialog have listeners for clicking the positive and negative buttons, but the program don't wait for one of those to be execute. What am I missing here?
13 years ago
Can you call the Service's methods without binding to it?

13 years ago

I'm trying to fallow this tutorial for building a media player for android.

The tutorial talks about a service class
The code for binding service from the tutorial dose not compile in my system.

but this one dose:

(maybe the tutorial use earlier api version then mine? I'm using Android 2.2, API Level 8. )

anyway, my code compile and the call to bindService return true, but still my service object is null.
also the object m_connection whitch is a ServiceConnection stays null after bindService().
m_connection is defined at the begiining of the activity class, along with all data members:

of caurse m_IAudioPlayer is null too. if i tray to call any of the service mmethod
via m_IAudioPlayer.method() I get the null pointer exception.
what am I doing wrong with binding the service? or init or communicate with it?

why do I need this aidl interface actually? I saw code examples that starts a service without
using this interface?

13 years ago

Thanks for your advice.
but I think i'm missing something.

Find a good place to get the dimensions of the device screen and base all your other values on those

isn't that bounds me to a specific screen size?
and even I will make a list of all possible screens and manage a lookup table for all possible dimensions,
I still need to update that list every time a new phone or tablet comes out. right?
I probably didnt understand you.

but is good to know that view size is avaliable at onDraw(). so overriding it sounds like a good strategy.

13 years ago
Hello again,

I'm trying to build a grid of N by N images in my UI.
This grid come with two different sizes, depending of what the user selected in the welcome screen. the two optional grids are positions inside a fix sized GridView, defined in the xml. the question is what should be the height and width of the Image view dimentions? it should be 1/4 of the gridView when user select a 4 by 4 grid, 1/6 if we whant 6 by 6 grid, and so on.

I tried to call gridView.getHeight() at my onCreate(), in order to use this to set my ImageView dimentions.
but getHeight() return zero. now I know that UI dimentions are set only after onCreate exits.

so what should I do?

I tried to set the imageView size with a set of hard coded values, depend of the grid size.
this work nice on my emulator, with a fixed sized screen. if I want to support different screen sizes and resulotions, this is the wrong way to go.

I also tried another strategy, with limited success:
I need the dimensions inside of the gridView's Adapter, where i find what image the user just clicked on. so lets pass a reference to the gridView into the adapter. the gridView should have done its onMeasure by the time we first call adapter.getView(int position, View convertView, ViewGroup parent);
right? so I tried this:

inside GameActivity.onCreate() :

and inside the adapter I have:

so will be able to find the gridView's dimentions when creating the Images.
the problem is that my GridView shows all images except the one in its top left corner.
now a click on any of the images on the grid and invokation of getView makes the top levt view to appear
but the bottom right image disappear, and vice versa. (attached image)

Any insight from experienced, please?

13 years ago
so it just a missing constructor?
maybe, in the case where the costume view don't need parameters in the constructor,
does the version that takes only context will suffice?

The log seems to me different then the one I posted, but then I noticed that edit it.
I'll try to handle logcat better next time.
13 years ago
OK, I find out how to see the logcat on eclipse and how to dump it into a text file.
but Java ranch don't allow to attach text files.
so I have to paste this huge amount of text here, I guess.

Also, I attached the java and xml code for this app, so you can have the context.
I don't sure how to read this. toward the end of the log there is a report on socketException and
one line saying: "Launch timeout has expired, giving up wake lock!"
is this related to my costume surface?

13 years ago
How do I view the logcat output on netbeans? or eclipse?
13 years ago
Hi all,

I want to build a gui with some buttons and my own surfaceView.

my XML looks like this

and in my activity I'm trying to load this layout:

but the app crush when calling setContentView.
it is also crush when I try to call
View view= this.getLayoutInflater().inflate(R.layout.main, null);
the next line here should be setContentView(view);

how this inflation should be done?
13 years ago