I'm really stuck here, trying to set a banner with ads-admob to my android app. I have done all the layout settings in the main.xml, also worked in the manifest file with the permissions, tried both XML and JAVA methods to show the ads and trying to make it work but I always get "could not get currentAdManager" from logcat in Eclipse. The application also crashes here, but works just fine without the admob settings. My admob SDK is GoogleAdMobAdsSdk-6.0.1.jar and I'm developing using phonegap .
I noticed that the command "import com.google.ads.*;" doesn't have the "AdManager" because when I insert individually the "import com.google.ads.AdManager;", I receive the error message "The import com.google.ads.AdManager cannot be resolved". My files:
My JAVA:
> package what.car.notes;
>
> import android.os.Bundle;
> import org.apache.cordova.*;
> import com.google.ads.AdView;
> import com.google.ads.AdManager; **- ERROR APEARS HERE**
> import com.google.ads.*;
>
> public class Cargeous21forActivity extends DroidGap {
> /** Called when the activity is first created. */
> #Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> super.loadUrl("file:///android_asset/www/index.html");
> setContentView(R.layout.main);
>
> dView adView = (AdView)this.findViewById(R.id.AdView);
> adView.loadAd(new AdRequest());
> }
> }
My LAYOUT file (main.xml):
> <?xml version="1.0" encoding="utf-8"?>
>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
> xmlns:myapp="http://schemas.android.com/apk/res/what.car.notes"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent"
> android:orientation="vertical">
>
> <com.admob.android.ads.AdView
> android:id="#+id/AdView"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> myapp:backgroundColor="#000000"
> myapp:primaryTextColor="#FFFFFF"
> myapp:secondaryTextColor="#CCCCCC"
> />
>
> </LinearLayout>
My MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="what.car.notes"
android:versionCode="4"
android:versionName="1.3" >
<uses-sdk android:minSdkVersion="7" />
<uses-library
android:name="com.google.ads.AdManager" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:value="i've put my correct id here" android:name="ADMOB_PUBLISHER_ID" />
<activity android:name="com.admob.android.ads.AdMobActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboard|keyboardHidden"
android:value="SQLite-NDK" />
<!-- Track Market installs -->
<receiver android:name="com.admob.android.ads.analytics.InstallReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
And finally, the attrs.xml:
> <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable
> name="com.admob.android.ads.AdView"> <attr name="backgroundColor"
> format="color" /> <attr name="primaryTextColor" format="color" />
> <attr name="secondaryTextColor" format="color" /> <attr
> name="keywords" format="string" /> <attr name="refreshInterval"
> format="integer" /> </declare-styleable> </resources>
Does anyone have already been through such a thing?
Please read the getting started guide for the Google AdMob SDK on Android. The example from which you got that code is from an old Google ads SDK before the Google AdMob Ads SDK rewrite.
Issues I can see on first pass:
You're manifest's activity definition is incorrect. See this page for the correct AdActivity activity definition.
You don't need attrs.xml. The SDK includes these attributes now.
I don't think the publisher id can be a meta-vale. You must specify the publisher id in your AdView XML definition.
Your AdView XML definition needs to have an adSize.
The new Google AdMob SDK doesn't have a com.google.ads.AdManager class.
Thanks Eric! Your answer helped me a lot to find the right code. The final code looks like this:
JAVA:
import android.os.Bundle;
import org.apache.cordova.*;
import android.app.Activity;
import android.os.Handler;
import com.google.ads.*;
import android.widget.*;
import android.widget.LinearLayout;
public class myactActivity extends DroidGap {
private static final String MY_AD_UNIT_ID = "a14fd7e04e46295";
private AdView adView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
//
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
LinearLayout layout = super.root; // this is the only change from the sample
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<com.google.ads.GoogleAdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</LinearLayout>
EVerthing worked since then... BUT! YEs, there is a but... 2 days later, with the incredible amount of $0,00 and 150 ads solicitacion, admob/google canceled my account!! I had heard their method are weird and remove developers for no reason at all and, with $0,00 and 150 views they cut me off of their program. Good part: I found some other ad services better than admob, but the minus side is that I'll have to figure out the code all over again...
Thanks anyway Eric!
Related
I need some assistance on my final capstone design project for my university. My question is, How can I develop an android studio code (Kotlin) for Facebook in order to show Live videos from a "Client" website?
I already have a working code that shows the client's website, just need to be able to show his Live videos. This work is to finish my bachelor's degree in ELECTRICAL engineering, so no previous experience in programming apart from the C++ classes that I took 3 years ago.
This is the code i have now,
class FacebookActivity : AppCompatActivity() {
private lateinit var callbackManager: CallbackManager
/**
* This creates the page for Facebook login
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_facebook)
// Initialize the Facebook Login callback manager
callbackManager = CallbackManager.Factory.create()
// Register a callback for the Facebook Login button
btnLogin.registerCallback(callbackManager, object : FacebookCallback<LoginResult> {
// If the Facebook Login is successful
override fun onSuccess(loginResult: LoginResult) {
Log.d("FacebookActivity", "Facebook token: " + loginResult.accessToken.token)
startFacebookPage()
}
// If the Facebook Login is cancelled
override fun onCancel() {
Log.d("FacebookActivity", "Facebook Login cancelled.")
}
// If there is an error during the Facebook Login
override fun onError(error: FacebookException) {
Log.d("FacebookActivity", "Facebook Login error: " + error.message)
}
})
// Check if the user is already logged in to Facebook
if (AccessToken.isCurrentAccessTokenActive()) {
startFacebookPage()
} else {
// Log in the user with read permissions if they are not already logged in
LoginManager.getInstance().logInWithReadPermissions(this, listOf("public_profile"))
}
}
// Start the Facebook page
private fun startFacebookPage() {
val facebookIntent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("https://www.facebook.com/radiodiosmedijonotecalles")
}
startActivity(facebookIntent)
}
/**
* This allows to go "back"
*/
override fun onSupportNavigateUp(): Boolean {
onBackPressedDispatcher.onBackPressed()
return true
}
}
And the Manifest;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher2"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher2_round"
android:supportsRtl="true"
android:theme="#style/Theme.RadioDiosMeDijoNoTeCalles"
tools:targetApi="33">
<activity
android:name=".ClientActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".AboutThisAppActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".FacebookActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="true" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="#string/facebook_client_token" />
<activity
android:name=".ZenoRadioActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".YouTubeActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".LinksActivity"
android:exported="false" />
<activity
android:name=".TwitchActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".DonationsActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|touchscreen|smallestScreenSize"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any and all Help will be greatly appreciated!
I want to create a test project works 'facebook login'.
I made with reference to the developers site and blog equal, But I met with an error message on xml.
[error massage]
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebooktest.zoit.facebooktest/com.facebooktest.zoit.facebooktest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.facebook.login.widget.LoginButton
[xml]
<com.facebook.login.widget.LoginButton
android:id="#+id/facebook_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp" />
[Manifest]
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebooktest.zoit.facebooktest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
</manifest>
[MainActivity]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
facebookLoginButton.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {...
...
public void onActivityResult(...
void geHashKey(){...
void geHashKey(){ ...
public void onResume(){ ...
public void onPause(){...
Do you know what's wrong? please help.
I know!
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_main);
"setContentView(R.layout.activity_main);"
I succeeded to move the this code below to Facebook code.
My Code is not showing the Toolbar on Kitkat .
Here is my ScreenShot for both the version of Android.
Kitkat version:
Lollipop version:
What might be the reason behind this.
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.global.market">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/image_front"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".detailactivity"
android:label="#string/app_name" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version" android:value="6111000" />
</application>
</manifest>
Styles.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
android:clickable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/exp_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="160dp"
android:indicatorRight="?android:attr/expandableListPreferredItemIndicatorRight"
android:background="#android:color/white"
android:footerDividersEnabled="true"
android:groupIndicator="#null">
</ExpandableListView>
<!--<ListView-->
<!--android:background="#android:color/white"-->
<!--android:id="#+id/menuList"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginTop="10dp" />-->
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
Build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
ext {
supportLibVersion = '23.4.0' // variable that can be referenced to keep support libs consistent
}
defaultConfig {
applicationId "com.global.market"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
compile 'com.google.android.gms:play-services:6.1.11'
}
AppBar by default has elevation which works after lollipop. So it is always visible despite the layouts hierarchy. But on lower version (below lollipop) the toolbar might be drawn below some other layout.
So reorder your layout items to make the toolbar visible.
Change your style.xml to this
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
and in MainActivity.java you are initiliaze two time ToolBar so remove second line this
toolbar = (Toolbar) findViewById(R.id.toolbar);
you don't need it.
Try this
Update style.xml
<resources>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name = "AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resource>
and also update the activity theme in AndroidManifest.xml file
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I've attempting to upgrade my Android project to compile with Android 5.0. I was using the appcompat-v7 library successfully before this. Now using ActionBarActivity and Theme.AppCompat causes the views in my fragment layout not to render or not to be visible. If I change it back to Activity and remove the appcompat theme, the views are visible again. Can anyone point out the configuration that I'm doing wrong? My Eclipse project is compiling with Android 5.0, Private Libraries of android-support-v4.jar and android-support-v7-appcompat.jar. Under Android dependencies is android-support-v7-appcompat.jar.
And I have the following code:
in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE something>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.ctest"
android:versionCode="33"
android:versionName="1.4.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18"/>
<application
android:icon="#drawable/ic_launcher"
android:label="My App"
android:allowBackup="true" >
<activity
android:name=".MyActivity"
android:theme="#style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In fragment_layout.xml:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE something>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Nothing here"
android:textColor="#color/blue" >
</TextView>
</LinearLayout>
In MyActivity.java:
package com.mycompany.ctest;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class MyActivity extends ActionBarActivity {
private FragmentManager mFM;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFM = getFragmentManager();
mFM.beginTransaction()
.add(android.R.id.content, new MyFragment(),"frag")
.commit();
}
}
And in MyFragment.java:
package com.mycompany.ctest;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MyFragment extends Fragment {
#Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved) {
return inflater.inflate(R.layout.fragment_layout,group,false);
}
}
EDIT: LogCat shows
12-13 10:10:09.709: E/ResourceType(1013): Style contains key with bad entry: 0x01010479
Although I think that must be irrelevant because if I add an Activity layout with a static fragment loaded instead of using the Fragment Manager, my view becomes visible. And I still get the Style contains key with bad entry message.
I finally added an activity layout with a blank frame layout with id.
activity_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Then used that id when adding fragments to the activity with .add or .replace instead of using android.R.id.content.
setContentView(R.layout.activity_layout);
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container,new MyFragment(), "frag")
.commit();
I still don't know why that works and why android.R.id.content was not working.
Try importing from support library instead of just "import android.app.Fragment;" ...hope this might help
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Im getting error at the bold line inside XYPlot.java class.
XYPlot.java :
package com.arise.plotme;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.series.XYSeries;
import com.androidplot.xy.*;
import com.arise.plotme.R;
import java.util.Arrays;
/**
* The simplest possible example of using AndroidPlot to plot some data.
*/
public class XYPlot extends Activity
{
private XYPlot mySimpleXYPlot;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.plot_xml);
// initialize our XYPlot reference:
**mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);**
// Create a couple arrays of y-values to plot:
Number[] series1Numbers = {12,2,4,3};// --x -lat
// Number[] series2Numbers = {1,2,10,3};
Number[] series3Numbers = {2,12,-2,7};// --y -lon
// Turn the above arrays into XYSeries':
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers), // --x // SimpleXYSeries takes a List so turn our array into a List
//SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
Arrays.asList(series3Numbers),//--y
"Series1"); // Set the display title of the series
// same as above
// XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");
// Create a formatter to use for drawing a series using LineAndPointRenderer:
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 200, 0), // line color
Color.rgb(0, 100, 0), // point color
null); // fill color (none)
// add a new series' to the xyplot:
**mySimpleXYPlot.addSeries(series1, series1Format);**
// same as above:
//mySimpleXYPlot.addSeries(series2,
// new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null));
// reduce the number of range labels
**mySimpleXYPlot.setTicksPerRangeLabel(3);**
// by default, AndroidPlot displays developer guides to aid in laying out your plot.
// To get rid of them call disableAllMarkup():
**mySimpleXYPlot.disableAllMarkup();**
}
}
*plot_xml.xml :*
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#+dimen/activity_vertical_margin"
android:paddingLeft="#+dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".XYPlot" >
<com.arise.plotme.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
title="XY Plot me"/>
</RelativeLayout>
*Plot_Me MAnifest :*
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arise.plotme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.arise.plotme.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.arise.plotme.XYPlot"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Actually I have two layout of xml because I have two activity.
This is my second activity, my first activity contain no error.
Any helps are much appreciated.
Please replace your manifest file to this.
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.arise.plotme.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.arise.plotme.XYPlot"
android:label="#string/app_name" >
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />