this here is driving me nuts...
I want to pass some Parameters with a Button Constructor
I did create myButton extending Button:
package com.canbluetoothinterface.utilities;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class myActivityStartButton extends Button implements OnClickListener {
protected EditText[] Array;
private String Name;
private String BufferName;
private Activity activityinstance;
public String[] sValues;
Class<?> cls;
private Method m;
public myActivityStartButton(String Name, Class<?>clsin, Context context) {
super(context);
cls = clsin;
activityinstance = (Activity) context;
setId(mygetId());
this.Name = Name;
init();
}
private void init(){
setOnClickListener(this);
}
public myActivityStartButton(String Name, Class<?>clsin, Context context, Method min) {
super(context);
this.cls = clsin;
this.Name = Name;
this.m = min;
activityinstance = (Activity) context;
setId(mygetId());
setTag(findViewById(mygetId()));
init();
}
#Override
public void setId(int id) {
super.setId(id);
}
private int mygetId() {
int id = 0;
BufferName = Name;
id = activityinstance.getResources().getIdentifier(BufferName, "id", activityinstance.getPackageName());
return id;
}
#Override
public void onClick(View v) {
try {
m.invoke(null, (Object)null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent(activityinstance, cls );
activityinstance.startActivity(intent);
}
}
In my Activity I call:
Start = new myActivityStartButton("act_testdriveconfiguration_btn_start", DeviceListActivity.class, this, mstartbutton);
But my OnClick is never called...
What am I doing wrong?
Thank you
1.double check your init() is called.
The following code works for me.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.main_container);
SomeButton btn = new SomeButton(this);
layout.addView(btn);
}
private class SomeButton extends Button implements OnClickListener {
public SomeButton(Context context) {
super(context);
init();
}
private void init() {
setOnClickListener(this);
}
#Override
public void onClick(View v) {
Log.w("log", "click");
}
}
NOTE:
if your button is created in xml, you need these constructors.
public setParams(String Name, Class<?>clsin,etc params)
{
//saving params
}
public SomeButton(Context context) {
super(context);
init();
}
public SomeButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SomeButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
Related
I am actually searching for an android clock view whose time can be set in the activity and then it will start working from that setted time.I saw the TextClock view but it seemed that only the timezone can be set.Can anyone help me?
Use this class, might help you, You can change date time whatever you want
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.SystemClock;
import android.provider.Settings;
import android.support.v7.widget.AppCompatTextView;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import java.util.Calendar;
public class DigitalClock extends AppCompatTextView {
Calendar mCalendar;
private FormatChangeObserver mFormatChangeObserver;
private Runnable mTicker;
private Handler mHandler;
private boolean mTickerStopped = false;
String mFormat;
public DigitalClock(Context context) {
super(context);
initClock();
}
public DigitalClock(Context context, AttributeSet attrs) {
super(context, attrs);
initClock();
}
private void initClock() {
if (mCalendar == null) {
mCalendar = Calendar.getInstance();
}
}
#Override
protected void onAttachedToWindow() {
mTickerStopped = false;
super.onAttachedToWindow();
mFormatChangeObserver = new FormatChangeObserver();
getContext().getContentResolver().registerContentObserver(
Settings.System.CONTENT_URI, true, mFormatChangeObserver);
setFormat();
mHandler = new Handler();
mTicker = new Runnable() {
public void run() {
if (mTickerStopped) return;
mCalendar.setTimeInMillis(System.currentTimeMillis());
setText(DateFormat.format(mFormat, mCalendar));
invalidate();
long now = SystemClock.uptimeMillis();
long next = now + (1000 - now % 1000);
mHandler.postAtTime(mTicker, next);
}
};
mTicker.run();
}
#Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mTickerStopped = true;
getContext().getContentResolver().unregisterContentObserver(
mFormatChangeObserver);
}
private void setFormat() {
mFormat = "dd MMM yy , hh:mm ss a ";
}
private class FormatChangeObserver extends ContentObserver {
public FormatChangeObserver() {
super(new Handler());
}
#Override
public void onChange(boolean selfChange) {
setFormat();
}
}
#Override
public CharSequence getAccessibilityClassName() {
//noinspection deprecation
return DigitalClock.class.getName();
}
}
I'm new to Android and I have been struggling to draw on canvas a rectangle and text where the size of the rectangle, the text and the color depend on values selected from a MySql database.
I managed to get data selected inside my Activity, but I just can't figure it out how to pass the MySql data to the ondraw() method so I can draw the rectangle and text using the data.
Any help will be greatly appreciated.
public class MyTankActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
int useridInt = intent.getIntExtra("userid", -1);
String userid = useridInt+"";
Response.Listener<String> responseListener = new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
int success = jsonResponse.getInt("success");
JSONArray tank_data = jsonResponse.getJSONArray("tank_data");
if (success == 1) {
int i;
for(i=0;i<tank_data.length();i++){
// Log.v("Result--", "" + tank_data.getString(i));
JSONObject tankObj = tank_data.getJSONObject(0);
String location = (String) tankObj.getString("Location");
String color = (String) tankObj.getString("Color");
String Level = (String) tankObj.getString("Level");
}
} else {
// No records found in database
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
MyTankRequest myTankRequest = new MyTankRequest(userid, responseListener);
RequestQueue queue = Volley.newRequestQueue(MyTankActivity.this);
queue.add(myTankRequest);
setContentView(new TankView(this));
}
}
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<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="com.nivelsonic.nivelsonic.MyTankActivity"
android:background="#AEECFF">
<com.nivelsonic.nivelsonic.TankView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
TankView class:
package com.nivelsonic.nivelsonic;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class TankView extends View {
private Paint _paintTank = new Paint();
private Path _path = new Path();
public TankView(Context context) {
super(context);
// TODO Auto-generated constructor stub
init(null, 0);
}
public TankView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
init(attrs, 0);
}
public TankView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
init(attrs, 0);
}
private void init(AttributeSet attrs, int defStyle) {
_paintTank.setColor(Color.RED);
_paintTank.setAntiAlias(true);
_paintTank.setStyle(Paint.Style.STROKE);
}
#Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
// canvas.drawText();
// canvas.rect();
}
}
One suggestion:
Move JSON data to global variables
public class MyTankActivity extends AppCompatActivity {
String location;
String color;
String Level;
//....
And change setContentView with different constructor of TankView that allows to pass the obtained data:
setContentView(new TankView(this, location, color, Level));
Modify the constructor of TankView accordingly, also add some variables to TankView to store this values:
public TankView(Context context, String loc, String color, String level) {
super(context);
init(null, 0);
this.location = loc;// ... do the same with color/level
...
}
Modify the onDraw after you get the data
#Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
//using this.Location, color, text
// canvas.drawText();.
// canvas.rect();
}
i have problem on my on Attach its doing red line on him and writing me :
"overrides deprecated method in 'android.support.v4.app.Fragment' "
Please help me understand what i am doing wrong ?
ty you for all the helpers !!
package com.example.omermalka.memecreator;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
/**
* Created by omermalka on 14/11/2015.
*/
public class TopSectionFragment extends Fragment {
private static EditText TopText;
private static EditText BottomText;
TopSectionListener acitivtyCommander;
public interface TopSectionListener{
public void createMime(String top , String Bottom);
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try{
acitivtyCommander = (TopSectionListener) activity;
}catch (ClassCastException e){
throw new ClassCastException(activity.toString());
}
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.top_section_fragment, container, false);
TopText = (EditText) view.findViewById(R.id.TopTextInput);
BottomText = (EditText) view.findViewById(R.id.BottomTextInput);
final Button button = (Button) view.findViewById(R.id.BottomTextInput);
button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
buttonClicked(v);
}
}
);
return view;
}
public void buttonClicked(View v) {
acitivtyCommander.createMime(TopText.getText().toString(),BottomText.getText().toString());
}
}
You need to change
public void onAttach(Activity activity)
to
public void onAttach(Context context)
Final code:
#Override
public void onAttach(Context context) {
super.onAttach(context);
try {
acitivtyCommander = (TopSectionListener) context;
} catch (ClassCastException e){
throw new ClassCastException(context.toString());
}
}
I am trying to overlay a drawing on top of a camera preview. I made two custom class extended from SurfaceView: one for the overlay, and one for the cam.
Here is my logcat (only the "Caused by" statements) :
04-11 19:58:06.549: W/dalvikvm(867): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-11 19:58:06.609: E/AndroidRuntime(867): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class com.example.gui_v9.Activity1.CamView
04-11 19:58:06.609: E/AndroidRuntime(867): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.gui_v9.Activity1.CamView" on path: /data/app/com.example.gui_v9-2.apk
The second error where it cannot find the class, is because it did not inflate.
Eclipse Graphical Layout successfully compiles the xml code and gives a decent preview. Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.gui_v9.Activity1.CamView
android:id="#+id/camview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<com.example.gui_v9.Activity1.OverlayView
android:id="#+id/overlay"
android:layout_width="200dp"
android:layout_height="200dp"/>
</FrameLayout>
I tried to change the flags from
<com.example.gui_v9.Activity1.OverlayView .../>
to
<com.example.gui_v9.Activity1.OverlayView ...></com.example.gui_v9.Activity1.OverlayView>
or to
<SurfaceView class="com.example.gui_v9.Activity1$OverlayView" ... />
or even
<SurfaceView class="com.example.gui_v9.Activity1$OverlayView" ... ></SurfaceView>
without luck. In the latter case, I have a casting problem (CamView cannot be casted in SurfaceView) and Eclipse's XML Graphical Layout fails to render, so I m guessing that the first one takes me further in the compiling process.
You may also take a look at my main activity:
package com.example.gui_v9;
import java.io.IOException;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.hardware.Camera;
public class Activity1 extends Activity {
CamView camview = null;
OverlayView overlay = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
camview = (CamView) findViewById(R.id.camview);
overlay = (OverlayView) findViewById(R.id.overlay);
overlay.getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
public static class CamView extends SurfaceView implements SurfaceHolder.Callback {
Camera cam = null;
SurfaceHolder camviewholder = null;
public CamView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CamView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public CamView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
if (cam!=null) {
try {
cam.setPreviewDisplay(camviewholder);
}
catch (IOException e) {
}
cam.startPreview();
}
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
cam = Camera.open();
}
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
cam.stopPreview();
cam.release();
}
}
public static class OverlayView extends SurfaceView implements SurfaceHolder.Callback {
private Paint paint = new Paint();
OverlayThread overlaythread = null;
public OverlayView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public OverlayView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public OverlayView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
#Override
public void onDraw(Canvas canvas) {
paint.setColor(Color.BLUE);
canvas.drawCircle(100, 100, 100, paint);
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
setWillNotDraw(false); //Allows us to use invalidate() to call onDraw()
overlaythread = new OverlayThread(getHolder(), this);
overlaythread.setRunning(true);
overlaythread.start();
}
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
try {
overlaythread.setRunning(false);
overlaythread.join();
}
catch (InterruptedException e) {
}
}
}
public static class OverlayThread extends Thread {
private OverlayView overlay;
private SurfaceHolder overlayholder;
private boolean _run = false;
public OverlayThread(SurfaceHolder _overlayholder, OverlayView _overlay) {
overlayholder = _overlayholder;
overlay = _overlay;
}
public void setRunning(boolean run) {
_run = run;
}
#Override
public void run() {
Canvas c;
while (_run) {
c = null;
try {
c = overlayholder.lockCanvas(null);
synchronized (overlayholder) {
overlay.invalidate();
}
}
finally {
if (c != null) {
overlayholder.unlockCanvasAndPost(c);
}
}
}
}
}
}
As you can see, I have the three constructors for each classes (with 1,2 and 3 arguments) which is a common error in inflating class failure.
I got this to work when I implemented CamView and OverlayView in two separate classes (CamView.java and OverlayView.java), respectively. So I don't understand why importing classes makes it work. Maybe something with the static workspace?
Thank yall for your help!
I am creating a live wallpaper settings activity. It has a few seek bars and an Ad Mob ad view. Every time I touch one of the seek bars the ad temporarily disappears and then reloads a new add. However, the ad does not change when any of the other preferences are touched. How do I stop the ad from reloading when a seek bar preference is touched? I am pretty stumped on this one :-). Code follows:
The ad preference class:
import android.app.Activity;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class AdPreference extends Preference {
public AdPreference(Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);}
public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);}
public AdPreference(Context context) {super(context);}
#Override
protected View onCreateView(ViewGroup parent) {
// this will create the linear layout defined in ads_layout.xml
View view = super.onCreateView(parent);
// the context is a PreferenceActivity
Activity activity = (Activity)getContext();
// Create the adView
AdView adView = new AdView(activity, AdSize.BANNER, "a151390e12917b5");
((LinearLayout)view).addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.addTestDevice("23392C83B8B55DE893A18286CB92DDA2");
request.addTestDevice("E1BAA0317138AEE05268B2E4F76B2D3F");
adView.loadAd(request);
return view;
}
}
The seek bar class:
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class SeekBarPreference extends Preference implements OnSeekBarChangeListener {
private final String TAG = getClass().getName();
private static final String ANDROIDNS="http://schemas.android.com/apk/res/android";
private static final String ROBOBUNNYNS="http://robobunny.com";
private static final int DEFAULT_VALUE = 50;
private int mMaxValue = 100;
private int mMinValue = 0;
private int mInterval = 1;
private int mCurrentValue;
private String mUnitsLeft = "";
private String mUnitsRight = "";
private SeekBar mSeekBar;
private TextView mStatusText;
public SeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
initPreference(context, attrs);
}
public SeekBarPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initPreference(context, attrs);
}
private void initPreference(Context context, AttributeSet attrs) {
setValuesFromXml(attrs);
mSeekBar = new SeekBar(context, attrs);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
}
private void setValuesFromXml(AttributeSet attrs) {
mMaxValue = attrs.getAttributeIntValue(ANDROIDNS, "max", 100);
mMinValue = attrs.getAttributeIntValue(ROBOBUNNYNS, "min", 0);
mUnitsLeft = getAttributeStringValue(attrs, ROBOBUNNYNS, "unitsLeft", "");
String units = getAttributeStringValue(attrs, ROBOBUNNYNS, "units", "");
mUnitsRight = getAttributeStringValue(attrs, ROBOBUNNYNS, "unitsRight", units);
try {
String newInterval = attrs.getAttributeValue(ROBOBUNNYNS, "interval");
if(newInterval != null)
mInterval = Integer.parseInt(newInterval);
}
catch(Exception e) {
Log.e(TAG, "Invalid interval value", e);
}
}
private String getAttributeStringValue(AttributeSet attrs, String namespace, String name, String defaultValue) {
String value = attrs.getAttributeValue(namespace, name);
if(value == null)
value = defaultValue;
return value;
}
#Override
protected View onCreateView(ViewGroup parent){
RelativeLayout layout = null;
try {
LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (RelativeLayout)mInflater.inflate(R.layout.seek_bar_preference, parent, false);
}
catch(Exception e)
{
Log.e(TAG, "Error creating seek bar preference", e);
}
return layout;
}
#Override
public void onBindView(View view) {
super.onBindView(view);
try
{
// move our seekbar to the new view we've been given
ViewParent oldContainer = mSeekBar.getParent();
ViewGroup newContainer = (ViewGroup) view.findViewById(R.id.seekBarPrefBarContainer);
if (oldContainer != newContainer) {
// remove the seekbar from the old view
if (oldContainer != null) {
((ViewGroup) oldContainer).removeView(mSeekBar);
}
// remove the existing seekbar (there may not be one) and add ours
newContainer.removeAllViews();
newContainer.addView(mSeekBar, ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
catch(Exception ex) {
Log.e(TAG, "Error binding view: " + ex.toString());
}
updateView(view);
}
/**
* Update a SeekBarPreference view with our current state
* #param view
*/
protected void updateView(View view) {
try {
RelativeLayout layout = (RelativeLayout)view;
mStatusText = (TextView)layout.findViewById(R.id.seekBarPrefValue);
mStatusText.setText(String.valueOf(mCurrentValue));
mStatusText.setMinimumWidth(30);
mSeekBar.setProgress(mCurrentValue - mMinValue);
TextView unitsRight = (TextView)layout.findViewById(R.id.seekBarPrefUnitsRight);
unitsRight.setText(mUnitsRight);
TextView unitsLeft = (TextView)layout.findViewById(R.id.seekBarPrefUnitsLeft);
unitsLeft.setText(mUnitsLeft);
}
catch(Exception e) {
Log.e(TAG, "Error updating seek bar preference", e);
}
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int newValue = progress + mMinValue;
if(newValue > mMaxValue)
newValue = mMaxValue;
else if(newValue < mMinValue)
newValue = mMinValue;
else if(mInterval != 1 && newValue % mInterval != 0)
newValue = Math.round(((float)newValue)/mInterval)*mInterval;
// change rejected, revert to the previous value
if(!callChangeListener(newValue)){
seekBar.setProgress(mCurrentValue - mMinValue);
return;
}
// change accepted, store it
mCurrentValue = newValue;
mStatusText.setText(String.valueOf(newValue));
persistInt(newValue);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
notifyChanged();
}
#Override
protected Object onGetDefaultValue(TypedArray ta, int index){
int defaultValue = ta.getInt(index, DEFAULT_VALUE);
return defaultValue;
}
#Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
if(restoreValue) {
mCurrentValue = getPersistedInt(mCurrentValue);
}
else {
int temp = 0;
try {
temp = (Integer)defaultValue;
}
catch(Exception ex) {
Log.e(TAG, "Invalid default value: " + defaultValue.toString());
}
persistInt(temp);
mCurrentValue = temp;
}
}
}
The xml layout for the settings activity:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:robobunny="http://robobunny.com"
android:key="disco_wormhole_settings" >
<com.package.name.and.AdPreference
android:layout_width="fill_parent"
androidLlayout_height="wrap_content" />
<Preference
android:key="title"
android:summary="#string/settings_summary"
android:title="#string/settings_title" />
<com.package.name.and.SeekBarPreference
android:defaultValue="50"
android:key="flight_speed"
android:max="100"
android:progressDrawable="#drawable/seek_bar_progress"
android:summary="#string/flight_speed_summary"
android:title="#string/flight_speed_title"
robobunny:min="1"
robobunny:unitsLeft=""
robobunny:unitsRight="%" />
<com.package.name.and.SeekBarPreference
android:defaultValue="30"
android:key="num_rings"
android:max="40"
android:progressDrawable="#drawable/seek_bar_progress"
android:summary="#string/num_rings_summary"
android:title="#string/num_rings_title"
robobunny:min="1"
robobunny:unitsLeft=""
robobunny:unitsRight="" />
<com.package.name.and.SeekBarPreference
android:defaultValue="50"
android:key="particle_speed"
android:max="100"
android:progressDrawable="#drawable/seek_bar_progress"
android:summary="#string/particle_speed_summary"
android:title="#string/particle_speed_title"
robobunny:min="1"
robobunny:unitsLeft=""
robobunny:unitsRight="%" />
<Preference
android:summary="#string/colors_summary"
android:title="#string/colors_title" >
</Preference>
<Preference
android:defaultValue="0xff7d9fff"
android:key="color_one"
android:title="#string/color_one" >
</Preference>
<Preference
android:defaultValue="0xffff4b31"
android:key="color_two"
android:title="#string/color_two" >
</Preference>
<Preference
android:defaultValue="0xff64ff46"
android:key="color_three"
android:title="#string/color_three" >
</Preference>
<CheckBoxPreference
android:defaultValue="true"
android:key="use_space_dust"
android:title="#string/use_space_dust_title" />
<Preference
android:key="spacer"
android:title="#string/single_space" />
<Preference>
</Preference>
</PreferenceScreen>
Thanks in advance for your help,
Chris
I think onCreateView will be called multiple times so an ad request will be created every time. Try moving your admob code to something like onBind or onAttached.