[android-developers] Re: (beginner question) variables reset when I change device orientation?
Hint: Your Activity object is destroyed and then recreated on a rotation. This means that all your *new* Activity's fields have been set to 0/false/null again. Read the documentation about the `onSaveInstanceState(...)` method and how this stores data in the `savedInstanceState` parameter of the onCreate(...). On Tuesday, April 12, 2016 at 2:15:46 AM UTC-4, Jesse Clark wrote: > > I am new to Android development. I am experimenting with making a simple > app that displays a number that increases by one when the Up button is > pressed and decreases by one when the Down button is pressed. It works > correctly, except when I rotate the device from landscape to portrait or > vice versa, the number is reset to 0. Here is the code: > > package com.example.jz.counter; > > import android.app.Activity; > import android.content.Intent; > import android.os.Bundle; > import android.view.View; > import android.widget.Button; > import android.widget.TextView; > > public class MainActivity extends Activity implements View.OnClickListener > { > private int counter = 0; > private TextView OutputViewObject; > > @Override > protected void onCreate(Bundle savedInstanceState) > { > super.onCreate(savedInstanceState); > setContentView(R.layout.activity_main); > OutputViewObject = (TextView)findViewById(R.id.outputView); > OutputViewObject.setText("" + counter); > final Button buttonUp = (Button)findViewById(R.id.up_button); > final Button buttonDown = (Button)findViewById(R.id.down_button); > buttonUp.setOnClickListener(this); > buttonDown.setOnClickListener(this); > } > > @Override > public void onClick(View view) > { > switch (view.getId()) > { > case R.id.up_button: > counter++; > OutputViewObject.setText("" + counter); > break; > case R.id.down_button: > counter--; > OutputViewObject.setText("" + counter); > break; > } > } > } > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/82e379ef-d6d5-45b3-8b0d-880f25ec2db0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Beginner question on layouts
you should really read the documentation and do the plethora of tutorials Google provides. http://developer.android.com/guide/practices/screens_support.html Regarding the textview, that's what String Formatting is for (%.2f), look it up. On Friday, November 16, 2012 1:23:53 AM UTC+2, Brandon Cormier wrote: So I am new to Android development and have a question on layouts. When I create my app in Eclipse I have it set up so that I can see what it would look like on a Nexus S (4 in., 480 x 800). This looks great when I open it on my Exhibit 2 4G (3.7 in., 480 x 800), however it looks terrible when I open it on the Nexus 7. The buttons are in the wrong places and things just don't look the same. I am assuming this has to do with layouts? When I create a Windows application in java I use a layout such as the border layout, grid layout, flow layout, etch... and then add it to the frame. That way no matter how big I resize the window, it always looks the same. How do you do this in Android? Also, kinda off topic, but when displaying numbers in a textbox how do you make it so that it only shows up to the hundredths place? I am starting out creating apps that deal with tips, sale prices, etch, and don't need the final calculated price to be to the 5th decimal place. Thanks in advance! Brandon Samsung Exhibit 2 4G (T-Mobile) -- 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: Beginner Question
As you say, this structure is kind of messy, and even the name for it may strike you as a little 'messy';) It is called an anonymous class. You might want to look it up in the classic online tutorials originally created by Sun and now maintained by Oracle. I found it messy too, and I still find the standard indentation of the anonymous class annoying. But I decided to learn to live with it because 1) it is extremely common, and that not just in Android Java 2) there is one big, good thing it does for us: it spares the reader from having to track down all references to the class to verify that it really is instantiated only in that one place. This really does simplify debugging. It also explains why it is heavily used in Swing and JavaFX as well as Android. In fact, that is pretty much what the above-mentioned tutorials says at http://docs.oracle.com/javase/tutorial/uiswing/events/generalrules.html#innerClasses. On Feb 22, 8:58 am, rhaazy rha...@gmail.com wrote: Hi everyone. I'm not sure if this question belongs here but here goes.. I am a professional asp.net developer looking to get into android dev. I have been going through tutorials and having fun so far! I have a question related to how the tutorial is asking me to structure my code. The code is from a tutorial where I create a gridview and set up a click listener event: gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView? parent, View v, int position, long id) { Toast.makeText(HelloGridViewActivity.this, Position: + position, Toast.LENGTH_SHORT).show(); } }); To me this structure is kind of messy, what I would like to do is have the function, public void onItemClick be by itself, so that I can do something more along the lines of: (psudo code) gridview.setOnItemClickListener([somehow reference the function here]); Is what I'm asking possible? Does my question make sense? Is there a more appropriate group to ask this kind of question? Thanks very much for your time. -- 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: Beginner Question
This is more a Java question than an Android question. Let me give it a shot. The setOnItemClickListener(...) method requires an object that implements the OnItemClickListener interface as an argument. In your code snippet above, you are providing such an object by creating an anonymous class (you can Google that). While you can't save just the function somewhere else, you could create a class that implements the OnItemClickListener() interface (i.e. in its own file or even as an embedded class within the Java file that contains this code) and then create a new instance of it to pass to the setOnItemClickListener(). So, something like this: // Create this class somewhere else class MyOnClickListener implements OnItemClickListener() { // implement the required method } gridview.setOnItemClickListener(new MyOnClickListener()); On Feb 22, 11:58 am, rhaazy rha...@gmail.com wrote: Hi everyone. I'm not sure if this question belongs here but here goes.. I am a professional asp.net developer looking to get into android dev. I have been going through tutorials and having fun so far! I have a question related to how the tutorial is asking me to structure my code. The code is from a tutorial where I create a gridview and set up a click listener event: gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView? parent, View v, int position, long id) { Toast.makeText(HelloGridViewActivity.this, Position: + position, Toast.LENGTH_SHORT).show(); } }); To me this structure is kind of messy, what I would like to do is have the function, public void onItemClick be by itself, so that I can do something more along the lines of: (psudo code) gridview.setOnItemClickListener([somehow reference the function here]); Is what I'm asking possible? Does my question make sense? Is there a more appropriate group to ask this kind of question? Thanks very much for your time. -- 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: Beginner Question
Thanks for your input! Inbetween when I posted this and when I checked it again I ended up doing something similiar to what kookamonga did. After I read your post Mark, I added the implements OnItemClickListener to my activity and was able to do just as you said! This is exactly what I was looking for. So my next question is, in your opinions, what would be the better way to structure this? 1.) having my activity implement the OnItemClickListener 2.) creating an embedded class inside my activity that implements the OnItemClickListener I think I over estimated my ability to jump right into this without learning a bit more about the java language. Thanks again! -- 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: Beginner Question
Mark has way more experience than me, so I'll let him give the definitive answer... But my two cents are that it depends on the situation. :-) For example, if the widget for which you are writing the listener will only appear in this Activity, then having the Activity itself implement the interface is probably fine. But, say for example you're creating some layout that appears on all of your activities (maybe a common group of buttons or something like that), then I would create a separate reusable listener class that saves you from having to duplicate code. Please feel free to correct me if I'm wrong about this general approach. On Feb 23, 11:35 am, rhaazy rha...@gmail.com wrote: Thanks for your input! Inbetween when I posted this and when I checked it again I ended up doing something similiar to what kookamonga did. After I read your post Mark, I added the implements OnItemClickListener to my activity and was able to do just as you said! This is exactly what I was looking for. So my next question is, in your opinions, what would be the better way to structure this? 1.) having my activity implement the OnItemClickListener 2.) creating an embedded class inside my activity that implements the OnItemClickListener I think I over estimated my ability to jump right into this without learning a bit more about the java language. Thanks again! -- 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
Re: [android-developers] Re: Beginner Question
On 2/23/2012 11:55 AM, Kookamonga wrote: Mark has way more experience than me, so I'll let him give the definitive answer... But my two cents are that it depends on the situation. :-) I don't think there is a definitive answer here, only reasonable ones. For example, if the widget for which you are writing the listener will only appear in this Activity, then having the Activity itself implement the interface is probably fine. But, say for example you're creating some layout that appears on all of your activities (maybe a common group of buttons or something like that), then I would create a separate reusable listener class that saves you from having to duplicate code. Good point. I don't have a particular problem starting out with the anonymous class early in the project. When it's needed elsewhere It's a straight forward refactoring to extract the class. I'm pretty new to Android, at first glance, I'm not sure how useful this would be in the button group. Wouldn't each button need its own listener? Wouldn't there be an activity associated with them? On Feb 23, 11:35 am, rhaazyrha...@gmail.com wrote: I think I over estimated my ability to jump right into this without learning a bit more about the java language. Thanks again! http://javaranch.com is a pretty good resource for getting up to speed in the language. -- 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: Beginner Question
I'm not sure how useful this would be in the button group. Wouldn't each button need its own listener? Wouldn't there be an activity associated with them? Yes, each button would need its own listener. But if that button appeared on several activities - say it was a Settings button, or some such - you wouldn't need to duplicate the actual code performed in the onClick method several times. So, say the button appears in 2 activies, A and B. You could do this: Activity A ... onCreate(...) { ... settingsButton.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView? parent, View v, int position, long id) { // do something } }); } Activity B ... onCreate(...) { ... settingsButton.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView? parent, View v, int position, long id) { // do something } }); } Or, if you had created a separate class for the OnItemClickListener() and as long as the do something was the same, which it likely is in the case of something as generic as launching a settings activity, showing a toast, etc., you could do this: Activity A ... onCreate(...) { ... settingsButton.setOnItemClickListener(new MyOnItemClickListener()); } Activity B ... onCreate(...) { ... settingsButton.setOnItemClickListener(new MyOnItemClickListener()); } And now you have to update the common onClick actions in one place, etc. I think this works and would server to improve maintenance, readability... you know, all those good things. Now, here's something I'm not sure about at all, but I'm throwing it out there. I've seen an android:onClick attribute for buttons where you can specify the method to run on the click event. The docs say: This may also be a reference to a resource (in the form @[package:]type:name) ... So perhaps you can even get rid of the call to setOnItemClickListener(...) in all of the Activities that re-use the same button. But like I said, I've never played with this, so I'm not sure about it. On Feb 23, 1:24 pm, Ted Scott t...@hootinholler.com wrote: On 2/23/2012 11:55 AM, Kookamonga wrote: Mark has way more experience than me, so I'll let him give the definitive answer... But my two cents are that it depends on the situation. :-) I don't think there is a definitive answer here, only reasonable ones. For example, if the widget for which you are writing the listener will only appear in this Activity, then having the Activity itself implement the interface is probably fine. But, say for example you're creating some layout that appears on all of your activities (maybe a common group of buttons or something like that), then I would create a separate reusable listener class that saves you from having to duplicate code. Good point. I don't have a particular problem starting out with the anonymous class early in the project. When it's needed elsewhere It's a straight forward refactoring to extract the class. I'm pretty new to Android, at first glance, I'm not sure how useful this would be in the button group. Wouldn't each button need its own listener? Wouldn't there be an activity associated with them? On Feb 23, 11:35 am, rhaazyrha...@gmail.com wrote: I think I over estimated my ability to jump right into this without learning a bit more about the java language. Thanks again! http://javaranch.comis a pretty good resource for getting up to speed in the language. -- 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: Beginner question about Imageviews and Layouts
Why wasn't this posted? On Thu, Jan 20, 2011 at 10:41 AM, MartyParty marty7...@gmail.com wrote: hi guys, So all I want to do is display an image and draw a small white square on top of it. This square will be moved around by the user to select a portion of the image to crop. I wrote an XML layout file to handle the picture, but getting the white box to draw hasn't worked. I created an ImageView class and overrode the onDraw() method to draw my square, but I haven't been able to integrate that with the XML stuff. Is this the right way to go about this? please help!!! -- 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: Beginner question about Imageviews and Layouts
I've used bitmap overlays. Basically, after calling super.onDraw() I'll do a canvas.drawBitmap(). If you want to use a shape, ShapeDrawable is probably your bet. Here's a link to the info. http://developer.android.com/guide/topics/graphics/2d-graphics.html. Cheers, Bruce On Jan 20, 11:44 am, Marty Miller marty7...@gmail.com wrote: Why wasn't this posted? On Thu, Jan 20, 2011 at 10:41 AM, MartyParty marty7...@gmail.com wrote: hi guys, So all I want to do is display an image and draw a small white square on top of it. This square will be moved around by the user to select a portion of the image to crop. I wrote an XML layout file to handle the picture, but getting the white box to draw hasn't worked. I created an ImageView class and overrode the onDraw() method to draw my square, but I haven't been able to integrate that with the XML stuff. Is this the right way to go about this? please help!!! -- 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: Beginner question about Imageviews and Layouts
On Jan 20, 10:41 am, MartyParty marty7...@gmail.com wrote: I created an ImageView class and overrode the onDraw() method to draw my square, but I haven't been able to integrate that with the XML stuff. Are you asking how you use a custom view in an XML layout, or are you saying you know how to do this but it's not working the way you intended? You might want to share your layout so we can see what you're doing, otherwise we're guessing. Doug -- 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: Beginner question about creating new class Eclipse
Thanks Frank. But when I click browse button, in superclass selection dialog, I can't find any android class. I want to extend SurfaceView, but I can't find in super class selection dialog, only way is typing android.view.SurfaceView. I want to implement SurfaceHolder.Callback. I click add button, in new java class dialog to add a new interface, but I can't find any android interface :( Can help me please? On 7 jul, 23:33, Frank Weiss fewe...@gmail.com wrote: For the superclass, click the Browse button. Click the question mark in the lower left for an explanation of the Superclass Selection dialog. Similarly for the interfaces. -- 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: Beginner question about creating new class Eclipse
Solved. Sorry. I don't know why I had android.* in type filters, so I can't select any android class. Sorry again... :-P On 8 jul, 21:14, Sergio Viudes djpep...@gmail.com wrote: Thanks Frank. But when I click browse button, in superclass selection dialog, I can't find any android class. I want to extend SurfaceView, but I can't find in super class selection dialog, only way is typing android.view.SurfaceView. I want to implement SurfaceHolder.Callback. I click add button, in new java class dialog to add a new interface, but I can't find any android interface :( Can help me please? On 7 jul, 23:33, Frank Weiss fewe...@gmail.com wrote: For the superclass, click the Browse button. Click the question mark in the lower left for an explanation of the Superclass Selection dialog. Similarly for the interfaces. -- 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: Beginner Question: Is it possible to put each class into it's own java file in Eclispe?
but in all of the examples I've seen for android all of the methods and classes are all in one big java file Uhh On what sites did you find these examples? On Apr 20, 2:53 pm, ~ TreKing treking...@gmail.com wrote: On Tue, Apr 20, 2010 at 4:41 PM, Binxalot binxa...@gmail.com wrote: Is it possible to put my classes in to their own java files and then import those classes into a main program java file as needed like I do in C#? Yes. Which you could have found out on your own in about 5 minutes. --- -- TreKing - Chicago transit tracking app for Android-powered deviceshttp://sites.google.com/site/rezmobileapps/treking -- 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 athttp://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] Re: Beginner Question: Is it possible to put each class into it's own java file in Eclispe?
(This may or may not be more information than the OP needed. But there may be confusion there worth clarifying). Actually, Dianne, that's only true of top-level classes with the 'public' modifier. You can have top-level classes that are package- private in the same file -- but no more than one 'public'', and the file must be named with the same name as the class, plus the .java suffix. However -- that is ALMOST never done! Binxalot -- I'm afraid you're mistaken -- I'm reasonably certain that you have NOT seen all the methods and classes in one big java file. Either you've misunderstood what you were seeing, because it was all on one web page, or something else. Let's not worry about any confusion from web page formatting... If you were actually looking at .java files, then you were probably thrown off by one of these points: *) A java class definition cannot be split between files. All methods and fields will appear within the same file, which will contain the *complete* definition of that class. *) A java class definition can contain INNER class definitions. These are not independent definitions. If they do not include the 'static' keyword before the 'class' keyword, they can only be instantiated in the context of an instance of the outer class. If they DO include the 'static' keyword before the 'class' keyword, then you can view them as being somewhat akin to namespaces in intent. That is, the class name is available within the scope of that class; to be used elsewhere it needs to either be explicitly qualified with outer class name, e.g. (Outer.Inner, or com.example.java.Outer.Inner), or imported with the 'import static' statement. If you don't wish to do this, then you can instead use packages and make these inner classes top-level. Eclipse provides convenient commands to do this. Note that inner classes that have the 'public' modifier can be referenced outside the package, and those that have the 'protected' modifier can be referenced by subclasses of the outer class. Those with 'private' can only be accessed within the class, and those with no modifier can only be accessed by other classes within the same package. This is a bit more flexible than top-level classes, which can only be 'public' or default (i.e. private to the package). I hope this helps you read the code a bit easier. It's best to think of one .java file as being one complete unit; there may be inner and private classes, but it provides only one top-level class to other packages, and it provides the complete definition of that class. The compiler will output each class to its own .class file, including inner classes. They'll be in the same directory as other classes in the same package, but with names constructed to avoid conflicts. Anonymous (nameless) inner classes will get generated names. So all of these .class files have to be packaged up in an Java application. On Apr 20, 2:53 pm, Dianne Hackborn hack...@android.com wrote: The Java compiler requires that each top-level class be in its own source file. On Tue, Apr 20, 2010 at 2:41 PM, Binxalot binxa...@gmail.com wrote: I'm coming over from C# where I can make a namespace and then have each class placed into its own .cs file if I want, but in all of the examples I've seen for android all of the methods and classes are all in one big java file. Is it possible to put my classes in to their own java files and then import those classes into a main program java file as needed like I do in C#? -- 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.comandroid-developers%2Bunsubs cr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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 athttp://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
Re: [android-developers] Re: Beginner Question: Is it possible to put each class into it's own java file in Eclispe?
Ah good point. In fact I have had non-public classes combined in a public class's file. And usually quickly regretted it. :) On Wed, Apr 21, 2010 at 1:26 PM, Bob Kerns r...@acm.org wrote: (This may or may not be more information than the OP needed. But there may be confusion there worth clarifying). Actually, Dianne, that's only true of top-level classes with the 'public' modifier. You can have top-level classes that are package- private in the same file -- but no more than one 'public'', and the file must be named with the same name as the class, plus the .java suffix. However -- that is ALMOST never done! Binxalot -- I'm afraid you're mistaken -- I'm reasonably certain that you have NOT seen all the methods and classes in one big java file. Either you've misunderstood what you were seeing, because it was all on one web page, or something else. Let's not worry about any confusion from web page formatting... If you were actually looking at .java files, then you were probably thrown off by one of these points: *) A java class definition cannot be split between files. All methods and fields will appear within the same file, which will contain the *complete* definition of that class. *) A java class definition can contain INNER class definitions. These are not independent definitions. If they do not include the 'static' keyword before the 'class' keyword, they can only be instantiated in the context of an instance of the outer class. If they DO include the 'static' keyword before the 'class' keyword, then you can view them as being somewhat akin to namespaces in intent. That is, the class name is available within the scope of that class; to be used elsewhere it needs to either be explicitly qualified with outer class name, e.g. (Outer.Inner, or com.example.java.Outer.Inner), or imported with the 'import static' statement. If you don't wish to do this, then you can instead use packages and make these inner classes top-level. Eclipse provides convenient commands to do this. Note that inner classes that have the 'public' modifier can be referenced outside the package, and those that have the 'protected' modifier can be referenced by subclasses of the outer class. Those with 'private' can only be accessed within the class, and those with no modifier can only be accessed by other classes within the same package. This is a bit more flexible than top-level classes, which can only be 'public' or default (i.e. private to the package). I hope this helps you read the code a bit easier. It's best to think of one .java file as being one complete unit; there may be inner and private classes, but it provides only one top-level class to other packages, and it provides the complete definition of that class. The compiler will output each class to its own .class file, including inner classes. They'll be in the same directory as other classes in the same package, but with names constructed to avoid conflicts. Anonymous (nameless) inner classes will get generated names. So all of these .class files have to be packaged up in an Java application. On Apr 20, 2:53 pm, Dianne Hackborn hack...@android.com wrote: The Java compiler requires that each top-level class be in its own source file. On Tue, Apr 20, 2010 at 2:41 PM, Binxalot binxa...@gmail.com wrote: I'm coming over from C# where I can make a namespace and then have each class placed into its own .cs file if I want, but in all of the examples I've seen for android all of the methods and classes are all in one big java file. Is it possible to put my classes in to their own java files and then import those classes into a main program java file as needed like I do in C#? -- 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.comandroid-developers%2bunsubscr...@googlegroups.comandroid-developers%2Bunsubs cr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group athttp:// groups.google.com/group/android-developers?hl=en
[android-developers] Re: Beginner Question
Hello! When the emulator starts, it needs to load the OS like a real device; that's why you're seeing the word Android. It can take a long time to load, specially if it's loading Eclair. Once it starts though, you don't need to close it every time you build your app; Eclipse will install it again and start it in the emulator, you can see it in the Console. Hopes to be helpful, Dinesh -- 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: Beginner Question / Calendar API
Hi Andreas, Did you get the answer, put all user permissions in manifest and try. Thanks Nithin On Apr 8, 4:21 am, andreas andreas.str...@googlemail.com wrote: Hi, I'm really just a beginner and fiddling a little bit around with java and my G1. I'd like to create acalendarevent from the phone and learned, that there is no AndroidAPIfor thecalendar. I thought it should be possible to access the googlecalendarvia web. I googled a bit and found some code to try. If I start it as a java programm on my home pc, it works well and adds an event to mycalendar: com.google.gdata.client.calendar.CalendarService; import com.google.gdata.data.DateTime; import com.google.gdata.data.Person; import com.google.gdata.data.PlainTextConstruct; import com.google.gdata.data.extensions.EventEntry; import com.google.gdata.data.extensions.When; import com.google.gdata.util.ServiceException; import java.io.IOException; import java.net.URL; public class TestMyCal { /** * @param args */ public static void main(String[] args) throws IOException, ServiceException { // Set up the URL and the object that will handle the connection: URL postUrl = new URL(http://www.google.com/calendar/feeds/MYEMAIL/ private/full); CalendarService myService = new CalendarService(exampleCo- exampleApp-1); myService.setUserCredentials(MYNAME, MYPASSWORD); EventEntry myEntry = new EventEntry(); myEntry.setTitle(new PlainTextConstruct(My test event)); myEntry.setContent(new PlainTextConstruct(It might work.)); Person author = new Person(It's me, null, m...@home.com'); myEntry.getAuthors().add(author); DateTime startTime = DateTime.parseDateTime (2009-04-08T15:00:00-08:00); DateTime endTime = DateTime.parseDateTime (2009-04-08T17:00:00-08:00); When eventTimes = new When(); eventTimes.setStartTime(startTime); eventTimes.setEndTime(endTime); myEntry.addTime(eventTimes); // Send the request and receive the response: EventEntry insertedEntry = myService.insert(postUrl, myEntry); } } Great. Now I tried to put that into a Android application: package com.android.hello; import android.app.Activity; import android.os.Bundle; import com.google.gdata.client.calendar.CalendarService; import com.google.gdata.data.DateTime; import com.google.gdata.data.Person; import com.google.gdata.data.PlainTextConstruct; import com.google.gdata.data.extensions.EventEntry; import com.google.gdata.data.extensions.When; import com.google.gdata.util.AuthenticationException; import com.google.gdata.util.ServiceException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up the URL and the object that will handle the connection: URL postUrl = null; try { postUrl = new URL(http://www.google.com/calendar/feeds/MYEMAIL/ private/full); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } CalendarService myService = new CalendarService(exampleCo- exampleApp-1); try { myService.setUserCredentials(MYNAME, MYPASSWORD); } catch (AuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } EventEntry myEntry = new EventEntry(); myEntry.setTitle(new PlainTextConstruct(My test event)); myEntry.setContent(new PlainTextConstruct(It might work.)); Person author = new Person(It's me, null, m...@home.com'); myEntry.getAuthors().add(author); DateTime startTime = DateTime.parseDateTime (2009-04-08T15:00:00-08:00); DateTime endTime = DateTime.parseDateTime (2009-04-08T17:00:00-08:00); When eventTimes = new When(); eventTimes.setStartTime(startTime); eventTimes.setEndTime(endTime); myEntry.addTime(eventTimes); try { EventEntry insertedEntry = myService.insert(postUrl, myEntry); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); } setContentView(R.layout.main); } } The program just runs fine, no errors (not using