[android-developers] Re: Unique Random numbers
Assuming that you have a rand() function (that might repeat) and that your value range is [0, maxValue - 1]: Create an array of size maxValue and initialize everything to its index: for (int i = 0; i maxValue; ++i) { arr[i] = i; } Now do this: for (int i = 0; i maxValue - 1; ++i) { tmp = rand() % (maxValue - i); swap(arr[i], arr[maxValue - tmp]); } This shuffles the array in a random way, and walking through the array gives you values that can't repeat. On Mar 29, 11:04 am, Andrew Gregory andrew.greg...@gmail.com wrote: On 25 March 2011 20:45, Hassy hasith@gmail.com wrote: I want to display unique random numbers when button clicked. if a number appear once, that number should not appear again when button clicked. http://en.wikipedia.org/wiki/Linear_feedback_shift_register Looks random (and has been used as a random number generator at times), but doesn't repeat until the entire sequence has been used (maximal length). -- Andrew -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: strange behavior connecting to a php script
Thanks for your help, but the link is returning an error. Did you possibly mistype? On Mar 24, 2:55 am, Ekky Melynda ekkymelynda.e...@gmail.com wrote: Please visit my blogwww.mudaers.co.tv 2011/3/24 Aisthesis marsh...@marshallfarrier.com For a chess app I've been working on, I'm passing various types of information between players by calling remote php scripts, into which I pass post data, then get back a response based on data stored on the server. When testing one of these, I noticed that if I have the script send back move and game status information using '\n' to separate each entry, I only get the first line a lot of the time (when in my test case there should be 5). If, on the other hand, I don't use a line separator but instead separate entries just using ';' and put everything on the same line, it always worked. I just wondered what might be causing the unreliability when using '\n' instead of ';'. I guess for web pages '\n' is just whitespace, but that should, I would think, still be sent across the web just as the appropriate ASCII number--i.e., just like everything else. Any ideas what might be causing this behavior? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] strange behavior connecting to a php script
For a chess app I've been working on, I'm passing various types of information between players by calling remote php scripts, into which I pass post data, then get back a response based on data stored on the server. When testing one of these, I noticed that if I have the script send back move and game status information using '\n' to separate each entry, I only get the first line a lot of the time (when in my test case there should be 5). If, on the other hand, I don't use a line separator but instead separate entries just using ';' and put everything on the same line, it always worked. I just wondered what might be causing the unreliability when using '\n' instead of ';'. I guess for web pages '\n' is just whitespace, but that should, I would think, still be sent across the web just as the appropriate ASCII number--i.e., just like everything else. Any ideas what might be causing this behavior? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Can somebody suggest the best book or online resource for beginning android apps development?
Hello, Android definitely, although several others are also good references. On any of the books, try to get a 2011 publication date and definitely nothing older than 2010, as things are changing fast here, so even on the 2010 ones by the time they have made it through the publication process, there are likely to be some deprecated methods and they will definitely not make use of newer features. On Mar 21, 6:51 am, Narendra Padala checksumandr...@gmail.com wrote: Hi Flocks, Can somebody suggest the best book or online resource for beginning android apps development? Regard's Narendra -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: adding custom view in main.xml
did you use the fully qualified name when you put it in main.xml? e.g.: com.google.myapp.MyView if that doesn't do it, it's hard to debug without any code--also there are ways to draw a line without creating an extra custom view On Mar 17, 8:05 am, Vishwesh R. vish...@gmail.com wrote: hi, im a beginner i have created a Myview wich extends View class. i have drawn a line on this view (that is Myview) in its onDraw() method. i included my view in its main.xml it shows no error but when i run this application, it loads the canvas but im unable to see the line wich i have drawn in Myview the coordinate of the line do lie on canvas but it not visible after the application is run.. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: RadioGroup listener won't listen when buttons are not direct children
Thanks very much for the fast responses! I don't like the string concatention because the UI looks way better if I can make the message text a different color and size. Any suggestions on where to look to make my RadioGroup smart enough to look down the hierarchy or to drop the RadioGroup but keep the RadioButtons and manage their states by setting an onCheckedChangeListener? That would be my preferred solution, but I'm having trouble figuring out how to approach that. On Mar 13, 9:43 am, Kostya Vasilyev kmans...@gmail.com wrote: 13.03.2011 17:33, Marshall Farrier ?: Unfortunately, when I put the LinearLayout between the RadioButtons and the RadioGroup in the hierarchy, the RadioGroup OnClickListener() stopped working. You can always mange RadioButton states without a RadioGroup at all, by setting an OnCheckedChangeListener for all the buttons and tracking the current selection. It's only about a dozen lines of code. -- Kostya Vasilyev --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: RadioGroup listener won't listen when buttons are not direct children
awesome, tx Kostya! On Mar 13, 10:49 am, Kostya Vasilyev kmans...@gmail.com wrote: 13.03.2011 18:14, Aisthesis пишет: to drop the RadioGroup but keep the RadioButtons and manage their states by setting an onCheckedChangeListener? You will need something that implements OnCheckedChangeListener, might as well be your activity. Also something to store the currently selected radio button (e.g. private CompoundButton mCurrentButton). Then in onCreate, find all the radio buttons, and call button.setOnCheckedChangeListener for each. Finally, in the thing that implements OnCheckedChangeListener, something like this: @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked mCurrentButton != button) { mCurrentButton .setChecked(false); mCurrentButton = button; } } With the above you don't need a RadioGroup, and the currently selected option is always in mCurrentButton. -- Kostya -- Kostya Vasilyev --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: ProgressDialog not showing
I have the identical code in a similar situation, and the dialog showed up when i put in a timer before dismissing it. On mine, I've basically assumed that the data retrieval and processing is happening before the dialog really has a chance and am hoping that it will show up on phones that are using a slower 3G connection rather than a direct connection to the net. See it yours works if you throw in a timer to make it wait a few seconds before calling dismiss(). I'm betting that it will. I'll leave it to others to say whether it will work properly without the timer when actually deployed, as I haven't reached that point yet. On Mar 10, 6:12 pm, David Williams dwilli...@dtw-consulting.com wrote: All, I have my main class GolfCaddie.java which is called when the app is launched. GolfCaddie.java extends the TabActivity. I have 3 other classes, one for each tab, and at the moment these 3 classes just display text or graphics. In GolfCaddie.java the code is broken down as follows. Trying to simply it but can provide full code if needed: onCreate Set up Tabs Call initApp onCreateOptionsMenu Setup options Menu initApp ProgressDialog dialog = ProgressDialog.show(GolfCaddie.this, ,Initializing. Please wait..., true); Set up some variables Obtain deviceID Checks app name, and determines if this is the trial version or the full version Makes a call to my server and returns a JSONObject which is then decoded and certain items checked. If the app is the trial version AND the trial date has passed throw up an Alert with a message. Only option is to click OK which closes the App. Otherwise, if the app is the trial version through up an alert showing when the trial expires. dialog.dismiss(); That's it for now. Very crude but working. My problem is that the ProgressDialog never shows up, and all the code in initApp is done against a black screen, even though the onCreate sets the tab default to 0, which has a graphical backdrop. Probably not doing this in the correct way, but I was hoping for the ProgressDialog to display (againt Tab(0) which has the background image) whilst it performs the code in initApp. The call to my server is quick, but it's possible it can take upwards of 10-20 seconds depending upon connectivity and so wanted to at least show that something was happening. Having a black screen is not great at all. Would appreciate any help, and again, I can provide more detailed code if needed. TIA. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: ProgressDialog not showing
After some trouble figuring out how values are passed into the private class that extends AsyncTask (which, while compact, has a somewhat tricky syntax--at least for me), mine works the way it should. Thanks! On Mar 11, 4:00 pm, Kostya Vasilyev kmans...@gmail.com wrote: 12.03.2011 0:31, David Williams пишет: Does Java do certain things asynchronously then? I was thinking that things were done in a serial fashion but perhaps that is not the case. ProgressDialog.show is asynchronous, just like may other UI operations. Normally, this works, because the Android UI toolkit, just like many others (and not just for Java) is built around the event loop or message loop concept. The main thread runs in an infinite loop for processing messages, one at a time. Each message is a small task: this can include, for example, showing a dialog, redrawing a view, calling one of the application's callback methods. Your code: - Called by Android in onCreate - Calls setContentView - Calls ProgressDialog.show - Fetches stuff from the Internet - Returns from onCreate All of the above happens on the UI thread, which waits for your onCreate to return before proceeding to the next message (== small task). What your code in onCreate should do: - Call setContentView - Call ProgressDialog.show - Start an asynchronous operation to fetch stuff from the Internet - Return from onCreate - [ Android processes queued-up operations: draws your activity, shows the dialog ] The asynchronous fetch then should: - Run on its own thread; - When done, tell the application to hide the progress dialog and proceed. Hopefully, it starts to make more sense as you read through the links I've provided. This is probably the easiest way to implement asynchronous operations: http://developer.android.com/reference/android/os/AsyncTask.html -- Kostya Vasilyev --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How do i simply hit a remote php URL?
this can be improved a little imo, but it should get you going: http://www.aviransplace.com/2008/01/08/make-http-post-or-get-request-from-java/ On Mar 6, 5:23 am, chat2joe chat2...@gmail.com wrote: Hey guys, Sorry if this is a stupid question, I'm new to android and JAVA and have a project which is due very soon. I want to upload my gps positions to a MySQL database. I have a php file all ready to accept variables as file.php?lat=55long=22 . Once that url is entered... the lat and long go into my database. The closest I've seen for this is a HTTP request... I've been trying to get this working but it seems too complicated for my purpose as I don't need to listen for or process any return data. Is there a simple way to hit the url within a function? Ideally I'd like to have it triggered on gps location change, then also maybe a timout type delay to restrict that to only every 8 seconds. Thanks for any help on it! Joe -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: problem with empty cursor
that solved it, tx! i just waited to close the database until after closing the cursor, and no more error. (i had thought that the cursor had a life independent from the database, so very interesting fact!) On Mar 5, 6:44 pm, Mark Murphy mmur...@commonsware.com wrote: I am skeptical that your error is being caused by this code. Check out: http://stackoverflow.com/questions/4195089/what-does-invalid-statemen... On Sat, Mar 5, 2011 at 7:21 PM, Marshall Farrier marsh...@marshallfarrier.com wrote: The following code is supposed to test whether the SelfCursor is empty or not and to do different things depending on that result: private void register() { registered = false; db = new ChessDataBaseAdapter(this); db.open(); Cursor c = db.getSelfCursor(); Log.d(TAG, closing database); db.close(); if (c.moveToFirst()) { // TODO c.close(); } else { // Player has not yet registered Log.d(TAG, closing self cursor); c.close(); startRegistrationActivity(); } } moveToFirst() is supposed to return false if the cursor is empty, and that’s what I’m wanting here. But, when my cursor is empty, it’s also causing a bothersome error to show up in LogCat: Cursor invalid statement in fillWindow() The program doesn’t crash, but I still don’t like seeing the error. I gather that fillWindow() (in AbstractCursor) is supposed to copy data from the cursor to the CursorWindow, which is no doubt a problem if there’s nothing in the cursor. Is there a good way to test whether my cursor is empty without getting this error—i.e., without calling fillWindow()? I first tried c.getCount() 0 but got the same error. Any other ideas? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 3.1 Available! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Math question
center is (x0, y0) locX = x0 + radius * cos(angle) locY = y0 + radius * sin(angle) On Feb 27, 12:37 am, Scott Deutsch surger...@gmail.com wrote: I know that v = 2piR/T. How would polar coord work? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] updating problem in eclipse
i have everything installed fine in helios on windows up to SDK platform 2.3.3 api 10 revision 1, but when i try updating to sdk 3.0, api 11 revision 1, i get the message that a folder failed to be renamed or moved. the message box says the problem is typically caused by a program using the file or by anti-virus software, which should be disabled. so, i disabled everything in norton 360, and ie is closed, but the problem still occurs. i get the same problem on a couple of the development tools and a few of the google apis. any suggestions? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: updating problem in eclipse
Using the SDK manager outside of eclipse got everthing installed from the standpoint of the stand-alone SDK manager. But then when I start eclipse, it doesn't show sdk 3.0 as being installed (it does show up under installed packages in the standalone sdk manager). On Feb 28, 8:54 am, Kostya Vasilyev kmans...@gmail.com wrote: Are you running the update manager right inside Eclipse? If so, don't - close Eclipse and run the Android SDK Manager independently (form the Start menu). I just updated yesterday to Tools r10 and SDK Tools r3 and didn't get the error (used to get it with Tools r9). -- Kostya 28.02.2011 17:46, Aisthesis пишет: i have everything installed fine in helios on windows up to SDK platform 2.3.3 api 10 revision 1, but when i try updating to sdk 3.0, api 11 revision 1, i get the message that a folder failed to be renamed or moved. the message box says the problem is typically caused by a program using the file or by anti-virus software, which should be disabled. so, i disabled everything in norton 360, and ie is closed, but the problem still occurs. i get the same problem on a couple of the development tools and a few of the google apis. any suggestions? -- Kostya Vasilyev --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] replacing deprecated managedQuery() method
I was already struggling with some code from Professional Android 2 App Development that uses the managedQuery() method of Activity when I noticed that the method is deprecated anyway. The documentation says to use CursorLoader instead, and from what I can gather, LoaderManager also seems to be involved. The way the code stands, I somehow need first to get a Cursor that contains the data in ContactsContract.Contacts. Here's the code I'm needing to change: First, in onCreate() in my ContactSelector activity: codeIntent i = getIntent(); final Uri data = i.getData(); // managedQuery() is deprecated final Cursor c = managedQuery(data, null, null, null, null); String[] from = {ContactsContract.Contacts.DISPLAY_NAME}; int[] to = {R.id.contact_name}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_item_text_view, c, from, to); /code The point here is that I need a cursor to feed into SimpleCursorAdapter (or some other class that allows me to populate my list of contact_item_text_view text views). Then in the parent activity that calls ContactSelector using startActivityForResult(), I have this private method that gets called from onActivityResult (where data is of course the Intent that's passed into onActivityResult()): code private void addPlayer(Intent data) { Uri contactData = data.getData(); Cursor c = managedQuery(contactData, null, null, null, null); c.moveToFirst(); String name = contact + c.getString(c.getColumnIndexOrThrow(ContactsContract .Contacts._ID)) + : + c.getString(c.getColumnIndexOrThrow(ContactsContract .Contacts.DISPLAY_NAME)); // TODO Toast nameMessage = Toast.makeText(this, name, Toast.LENGTH_SHORT); nameMessage.show(); } /code Basically, I just need a good way to populate my contact list in the ContactSelector activity, then to receive the data back from the parent activity. The toast is just there for the moment to show me what I'm getting back. If it matters, I'm going to need to retrieve not only names but also phone numbers in the end, so some technique that would make it as easy as possible to deal with that aspect would also be nice. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en