public class ActivityGoogleMaps extends MapActivity {// map view shows as an error
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I try to import this:
import com.google.android.maps.MapActivity;
but when i type com. - google doesnt appear..
1- Go to Project Properties
2- From android tab, select Google API for your target platform
(for 2.2, select Google APIs-Platform 2.2 and things like that)
I think this can solve the problem
you will have to add map.jar to libs. though it is automatically added when we extends MapActivity.
Related
I am new to android studio and when i am about to start ,the error is noticed by me in the below snippet.i have recognised it by an indication in android studio.U can see below image to trace out my issue.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
when i go through that by clicking it shows 720 errors.What might be reason behind this and how to solve.Please help me.
http://i.stack.imgur.com/EayEp.png
This is standard practice. Your code should compile and run as is (judging by the screenshot at least)
Are you referring to the 720 errors in the actual system's class' onCreate method? That's the Android's system inner workings and you have no reason to go there right now as a beginner.
I want to retain the instance of an object on configuration changes using Fragments. And I want to support older versions of android using support library. So I extended FragmentActivity like this.
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class test extends FragmentActivity {
#Override
public void onCreate(Bundle state){
super.onCreate(state);
setRetainInstance(true);
}
}
But when I do this, Eclips complains that there is no such a thing as setRetainInstance. But when I change the FragmentActivity to Fragment every thing is OK.
what am I missing?
setRetainInstance(Boolean) is a method in Fragment class. not of FragmentActivity class...
and There is a support library for Fragments in Android SDK.
see at android-sdk/extras/android/support/v4/android-support-v4.jar
I am developing an android app using phonegap (cordova-2.1.0).
My MainActivity.java code is as following -
package com.app.myapp;
import android.os.Bundle;
import org.apache.cordova.*;
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Problem : Whenever I start the application, it shows MainActivity window first and then show the actual HTML code. Is there any way to get rid of MainActivity and show the HTML directly?
Thanks in Advance...
Add this to your AndroidManifest application tag:
android:theme="#android:style/Theme.NoTitleBar"
Should do the trick.
Ubuntu 11.10 ADT 16.01 Java 6 Eclipse Java EE Indigo SR1 - All latest release following android dev requirements.
I am just starting to learn coding for android and got to a tutorial on switching Activities. Using the New project android template, I made another test activity class identical to the first except for name.
package com.test.SwitchActivity;
import android.app.Activity;
import android.os.Bundle;
public class SwitchActivityActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
The problem is that when I use the Menifest editor edit the AndroidManifest.xml file - add button for the Application Node, the listbox is empty. All the tutorials I have found are populated with xml tag choices. Now, I can add the xml data manually - it is no problem. What is driving me nuts is not being able to figure out why it does not work for me as it is supposed to work. I don't find other people having the issue and I have re-installed everything at least once before coming here to post another question.
I just want to finish the tutorial and switch between two activities.
Here is a screenshot of what I describe. Anyone have any ideas as to why it does not work?
http://i.stack.imgur.com/Fwfbz.png
To create another activity
Create a new class "myactivity.java" that extends the Activity
Create android xml file with your UI items in it lets call it exampleactivity.xml (it should be in small letters with .xml extension and should be saved in res/layout folder).
In myactivity.java add the following method (same as above except exampleactivity replaced main)
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.exampleactivity);
}
}
create a button changeactivity in SwitchActivityActivity and initialize it in onCreate method of SwitchActivityActivity via
changeactivity = (Button) findViewById(R.id.newActivityButton);
create the following in onCreate method of SwitchActivityActivity
changeactivity.setOnClickListener(new OnClickListener() {
Intent i;
public void onClick(View v) {
i = new Intent(Intent.ACTION_DEFAULT);
i.setClass(SwitchActivityActivity.this, myactivity.class);
startActivity(i);
}
});
In the main.xml create a button and give the button id by
android:id="#+id/newActivityButton"
Finally add the following in AndroidManifest file after the SwitchActivityActivity activity tag
compile and run it.
I found this on android developers when i was trying to program a button:android developers blog: UI framework changes in Android 1.6
With Android 1.6, none of this is necessary. All you have to do is declare a public method in your Activity to handle the click (the method must have one View argument):
class MyActivity extends Activity { public void myClickHandler(View target){
// Do stuff
}
}
And then reference this method from your XML layout:
<Button android:onClick="myClickHandler" />
can smeone please explain this code to me? I am a beginner in programming, and I don't know what to put in the //do stuff space? I need to reference another activity so i can open another screen. And do i still need to have an activity and put a block of program in the class? this is the code i am using in the class at the moment. Please tell me if i need to update it to use this method:
package com.duncan.hello.world;
import com.duncan.hello.world.R;
import android.app.Activity;
import android.os.Bundle;
public class OtherActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
}
}
You put what you want to happen when the button is clicked in the // do stuff part.
You only need to update your code if you're using a button click handler in this fashion.
You might want to start with something a bit simpler, and perhaps not target Android 1.6.