Need Help For integrating interstitials admob on my quotes android template - java

I have quotes android app came with admob banner template but I don't how to integrate interstitials admob to this project. Template with database with sqlite.
Here codes for MainActivity.java
package com.XXXX.MYpackage;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import com.XXXX.MYpackage.R;
import com.XXXX.MYpackage.activity.AbstractContentActivity;
import com.XXXX.MYpackage.activity.FavouristList;
import com.XXXX.MYpackage.activity.QuoteList;
import com.XXXX.MYpackage.activity.SearchActivity;
import com.XXXX.MYpackage.activity.SettingActivity;
import com.XXXX.MYpackage.db.DataHeper;
import com.XXXX.MYpackage.db.entity.QOD;
import com.XXXX.MYpackage.utils.CustomSharePreferences;
import com.XXXX.MYpackage.utils.WriteLog;
public class MainActivity extends AbstractContentActivity{
private ImageButton btn_author;
private ImageButton btn_quotes;
private ImageButton btn_fav;
private ImageButton btn_facebook;
private ImageButton btn_search;
final static int AUTHORIZE_ACTIVITY_RESULT_CODE = 10;
private DataHeper dataHeper;
private TextView tv_body;
private PendingIntent mAlarmSender;
#Override
protected void initView() {
// TODO Auto-generated method stub
super.initView();
CustomSharePreferences sharePreferences = new
CustomSharePreferences(getApplicationContext());`
btn_author = (ImageButton)findViewById(R.id.d_authors_btn);
btn_quotes = (ImageButton)findViewById(R.id.d_quotes_btn);
btn_fav = (ImageButton)findViewById(R.id.d_favs_btn);
tv_body = (TextView)findViewById(R.id.d_qod_body);
btn_facebook = (ImageButton)findViewById(R.id.actionbar_facebook_btn);
btn_search = (ImageButton)findViewById(R.id.actionbar_search_btn);
dataHeper = new DataHeper(getApplicationContext());
btn_author.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
WriteLog.d("ThangTB", "onclick image");
Intent i = new Intent(getApplicationContext(), SettingActivity.class);
startActivity(i);
}
});
btn_quotes.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
WriteLog.d("ThangTB", "onclick image");
Intent i = new Intent(getApplicationContext(), QuoteList.class);
startActivity(i);
}
});
btn_fav.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
WriteLog.d("ThangTB", "onclick image");
Intent i = new Intent(getApplicationContext(), FavouristList.class);
startActivity(i);
}
});
btn_facebook.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
facebook();
}
});
btn_search.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intentSearch = new Intent(getApplicationContext(), SearchActivity.class);
startActivity(intentSearch);
}
});
mAlarmSender = PendingIntent.getService(MainActivity.this,
0, new Intent(MainActivity.this, AlarmService_Service.class), 0);
// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime, 30*1000, mAlarmSender);
}
#Override
protected int getViewLayoutId() {
// TODO Auto-generated method stub
return R.layout.dashboard;
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
new GetData().execute();
super.onResume();
}
private class GetData extends AsyncTask<Object, Object, Object>{
private QOD quoteOfDay;
public GetData() {
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
quoteOfDay = dataHeper.getQOD();
return null;
}
#Override
protected void onPostExecute(Object result) {
if (quoteOfDay!=null) {
tv_body.setText(Html.fromHtml(quoteOfDay.getBody()));
}
super.onPostExecute(result);
}
}
public void facebook() {
Uri localUri = Uri.parse(getResources().getString(R.string.facebook_fanpage));
Intent localIntent = new Intent("android.intent.action.VIEW", localUri);
startActivity(localIntent);
}
}
Here is some xml codes from admob banner (quotepreview.xml) and others xml using same code for admob--- I think only this codes for admob banner.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:orientation="vertical" android:id="#id/qp_main_parent"
android:background="#drawable/bg_default" android:clickable="true"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="vertical" android:id="#id/widget99"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:id="#id/ad_holder" style="#style/AdHolder" />
<RelativeLayout android:background="#drawable/actionbar_bg"
android:paddingRight="5.0dip" android:layout_width="fill_parent"
android:layout_height="48.0dip"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<com.google.ads.AdViewandroid:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="k15XXX"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR,xxx2xxxx"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
<ImageViewandroid:background="#drawable/dashboard_bar_shadow"android:layout_width=
"fill_parent"android:layout_height="6.0dip"/>
</LinearLayout>
<ScrollViewandroid:id="#id/qp_body_wrapper"android:clickable="true"
android:layout_width="fill_parent"android:layout_height="fill_parent"android:
layout_marginTop="10.0dip"android:layout_above="#id/widget34"android:layout_below
="#id/widget99">
<LinearLayoutandroid:orientation="vertical"android:id="#id/qp_body_
wrapper_container"android:clickable="true"android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextViewandroid:textSize="18.0dip"android:gravity="left"android:id="#id/qp_body"
android:padding="10.0dip"android:clickable="true"android:layout_width=
"fill_parent"android:layout_height="wrap_content"style="#style/QuoteViewText"/>
</LinearLayout>
</ScrollView>
<LinearLayoutandroid:gravity="center"android:orientation="horizontal"android:id=
"#id/widget34"android:layout_width="fill_parent"android:layout_height=
"wrap_content"android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<Buttonandroid:id="#id/qp_previous_btn"android:background="#drawable/
state_left_arrow"android:layout_width="48.0dip"android:layout_height=
"48.0dip"android:layout_margin="12.0dip"/>
<Buttonandroid:id="#id/qp_random_btn"android:background="#drawable/state_
refresh_btn"android:layout_width="48.0dip"android:layout_height="48.0dip"
android:layout_margin="12.0dip"/>
<Buttonandroid:id="#id/qp_favourite"android:background="#drawable/
qp_fav_btn_normal"android:layout_width="48.0dip"android:layout_height=
"48.0dip"android:layout_margin="12.0dip"/>
<Buttonandroid:id="#id/qp_next_btn"android:background="#drawable/
state_right_arrow"android:layout_width="48.0dip"android:layout_height=
"48.0dip"android:layout_margin="12.0dip"/>
</LinearLayout>
</RelativeLayout>
Here is code from AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXXX.MYpackage"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.CustomDark" >
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"> >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.XXXX.MYpackage.Widget" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_generic" />
</receiver>
<service android:name="com.XXXX.MYpackage.AlarmService_Service"
android:process=":remote" />
<activity android:name=".MainActivity" android:screenOrientation="portrait"></activity>
<activity android:name=".activity.AuthorList" android:screenOrientation="portrait">>
</activity>
<activity android:name=".activity.AuthorQuoteList"
android:screenOrientation="portrait"></activity>
<activity android:name=".activity.QuoteView" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.QuoteList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.FavouristList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.CategoryList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.FilterList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.CategoryQuoteList"
android:screenOrientation="portrait"></activity>
<activity android:name=".activity.SearchActivity" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.HelpActivity" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.SettingActivity"
android:screenOrientation="portrait"></activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|
screenSize|smallestScreenSize"/>
</application>
</manifest>
Please help me integrate admob interstitial. Thank you

You don't need any extra layout or Manifest config to integrate interstitials, but you will need to add a small amount of code.
See https://developers.google.com/mobile-ads-sdk/docs/admob/advanced

Related

Splash screen activity not working

Hi have created splash screen as a separate project by using this link : http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/ . And it did worked on my emulator . However, when I implemented this in my app. It did not worked . I don' know whats wrong with my code. My main.java, splash screen.java and splash.xml are the following. Please note that I did define my activity in manifest file. Any help will be greatly appreciated...
MainActivity.Java
import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener {
private MediaPlayer mp;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
findViewById(R.id.button_1).setOnClickListener(this);
findViewById(R.id.button_2).setOnClickListener(this);
findViewById(R.id.button_3).setOnClickListener(this);
}
public void onClick(View v) {
int resId=1;
// Release any resources from previous MediaPlayer
if (mp != null) {
mp.release();
}
switch (v.getId()) {
case R.id.button_1: resId = R.raw.button_1; break;
case R.id.button_2: resId = R.raw.button_2; break;
case R.id.button_3:
startActivity(new Intent(MainActivity.this,SecondActivity.class));
return;
}
// Create a new MediaPlayer to play this sound
mp = MediaPlayer.create(this, resId);
mp.start();
}
}
SplashScreen.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_background" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/images235" />
</RelativeLayout>
Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Smit.yourbollywoodyourplaylist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".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=".SecondActivity"
android:label="#string/app_name"/>
</application>
</manifest>
It's not clear which package your SplashScreen.java lives in, but
android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
might need to be changed to
android:name=".SplashScreen"
You may have just pasted in the manifest definition from the sample project without adjusting the activity name to match your own project.

Unfortunately myandroidapps has stopped

I am very new to android apps development. I successfully signed my apps and installed on my phone Android Ver. 4.1.2. The codes below are my codes. May I know what is wrong? Thanks guys/girls :)
Activity_main.xml
<?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:id="#+id/relativeLayout1"
>
<Button
android:id="#+id/buttonFlashlight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Torch" /> </RelativeLayout>
MainActivity.java
package com.mkyong.android;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
//flag to detect flash is on or off
private boolean isLighOn = false;
private Camera camera;
private Button button;
#Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();
// if device support camera?
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (isLighOn) {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
}
}
});
}
}
myandroidapps Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" android:allowBackup="false">
<activity
android:label="#string/app_name"
android:name=".FlashLightActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
you forget to declare MainActivity Activity in AndroidManifest.xml. add it as:
....
<activity android:name=".MainActivity" />
....
</application>
....

Converting EditText to a String but still returning an EditText on LogCat

I'm trying to have a user fill out my EditText with a price... i.e. "20.00" and get the value from that edit text as a string. Then use that string as data to be uploaded as a value to "my server" a.k.a parse.com under the "Price" key. Whenever I run my emulator, fill out "20.00" in the edit text, and check my server a new entry never pops up. My logcat returns:
03-23 21:14:20.607: V/EditText(1697): 20.00
If I create another string above and simply give it a value. Then put it under the "Price" key instead of myString and run the emulator, my server will receive this and everything will workout.
Since the value set under the key "Price" is a string and my logcat is returning an EditText whenever I use myString, this is leading me to believe that I am using an EditText instead of a String even though I have looked up multiple tutorials/ answers that all say in order to get the string from an edit text you have to use:
price = (EditText) findViewById(R.id.editText1);
String newString = price.getText().toString();
which I have in my code.
Also, I have two SearchViews and two ListViews above that have search functionality so my code is a little lengthy. My code does not error out at all and it works fine besides for this minor hiccup.
TapDeal.java - problem class:
package com.alpha.dealtap;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.parse.Parse;
import com.parse.ParseObject;
public class TapDeal extends Activity {
Button b1;
String newString;
// List view
private ListView lv;
private ListView lv2;
// Listview Adapter
ArrayAdapter<String> adapter;
ArrayAdapter<String> adapter2;
// Search EditText
EditText inputSearch;
EditText inputSearch2;
EditText price;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
ArrayList<HashMap<String, String>> productList2;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tapdeal);
// Listview Data
String products[] = { "Dubra", "Keystone Light", "Keystone",
"Smirnoff", "Jack Daniels", "Captain Morgan", "Grey Goose",
"Burnetts", "Kettle One", "Corona", "Franzia", "Budweiser" };
String size[] = { "6 Pack", "12 Pack", "30 Pack", "750ml", "Handle",
"1 liter", "3 Liter Box", "Half Pint", "1 Pint" };
lv = (ListView) findViewById(R.id.list_view);
lv2 = (ListView) findViewById(R.id.list_view2);
inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch2 = (EditText) findViewById(R.id.inputSearch2);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.listitem,
R.id.product_name, products);
adapter2 = new ArrayAdapter<String>(this, R.layout.size, R.id.size,
size);
lv.setAdapter(adapter);
lv2.setAdapter(adapter2);
inputSearch.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// When user changed the Text
TapDeal.this.adapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
inputSearch2.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
TapDeal.this.adapter2.getFilter().filter(s);
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
b1 = (Button) findViewById(R.id.button1);
price = (EditText) findViewById(R.id.editText1);
String newString = price.getText().toString();
Parse.initialize(this, "xxxx", "yyyy");
ParseObject dealinfo = new ParseObject("Deals");
dealinfo.put("Brand", "Budweiser");
dealinfo.put("Size", "6");
dealinfo.put("Price", newString);
dealinfo.saveInBackground();
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v("EditText", price.getText().toString());
}
});
}
}
("xxxx" and "yyyy" are my private keys).
tapdeal.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Editext for Search -->
<EditText
android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Brand of Alcohol"
android:inputType="textVisiblePassword" />
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="52dp" />
<EditText
android:id="#+id/inputSearch2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Enter the Size"
android:inputType="textVisiblePassword" />
<ListView
android:id="#+id/list_view2"
android:layout_width="fill_parent"
android:layout_height="54dp"
android:layout_weight="0.16" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="Enter the Price"
android:inputType="numberDecimal" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="Tap it"
android:textSize="23dp" />
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alpha.dealtap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Search_Page"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.SEARCH_PAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".DealPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.DEALPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".StorePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.STOREPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Map"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.MAP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TapDeal"
android:label="TapDeal"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="com.alpha.dealtap.TAPDEAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for your help!
It's not entirely clear from your question what is happening and what you expect to happen, but it seems odd that the onClick() method of your listener only outputs to the log. My guess is that you want all of this code:
String newString = price.getText().toString();
ParseObject dealinfo = new ParseObject("Deals");
dealinfo.put("Brand", "Budweiser");
dealinfo.put("Size", "6");
dealinfo.put("Price", newString);
dealinfo.saveInBackground();
in your onClick() method so that it happens when the button is clicked, instead of in the onCreate() method as it is now. If that's not what you're trying to achieve, then you'll have to edit your question to make it a lot clearer.

Why isnt my activity starting?

I think there is a problem with my activities because it runs the splash screen fine but when it gets to home page it gives force close error. I also appreciate it if you can see if my home.java code is correct I basically wanna open other activities and for exit button to quit the application.
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.decrypter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".Home"
android:label="#string/title_activity_home" >
<intent-filter>
<action android:name="com.example.decrypter.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
home.java
package com.example.decrypter;
import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;
public class Home extends Activity implements OnItemSelectedListener {
Button btn_start,btn_about,btn_exit;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
btn_start = (Button) findViewById(R.id.btn_start);
btn_about = (Button) findViewById(R.id.btn_about);
btn_exit = (Button) findViewById(R.id.btn_exit);
btn_start.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
Intent start = new Intent(Home.this, MainPage.class);
Home.this.startActivity(start);
}
});
btn_about.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
Intent about = new Intent(Home.this, about.class);
Home.this.startActivity(about);
}
});
btn_exit.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.home, menu);
return true;
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
String.xml
<string name="app_name">decrypter</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main_page">MainPage</string>
<string name="title_activity_home">Home</string>
<string name="prompt">- </string>
<string-array name="numbers">
<item >1</item>
<item >2</item>
<item>3</item>
<item >4</item>
<item>5</item>
<item >6</item>
<item >7</item>
<item >8</item>
<item>9</item>
</string-array>
home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/btn_about"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/home" >
<Button
android:id="#+id/btn_start"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="183dp"
android:gravity="center"
android:text="Start" />
<Button
android:id="#+id/btn_about"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/btn_start"
android:layout_below="#+id/btn_start"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="About me" />
<Button
android:id="#+id/btn_exit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Button01"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:gravity="center"
android:text="Exit" />
</RelativeLayout>
In your main.java, either onClick or any other event, you have to call start activity for the home activity. Or if you want home activity to be the first to load then you can make home activity main and remove other main activities. Convert your Home activity to LAUNCHER activity.

Android onClickListener

SOLVED: Put my file in the wrong folder, my stupid mistake :)
Anyone knows why this won't work? It just doesn't do anything. I have everything in the Main XML defined properly i think, but i feel like something is missing here.
I am new to Java/Android developing but i was using VB.NET for a long time.
package com.example.myfirstapplication;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.os.Bundle;
import android.app.Activity;
public class Main extends Activity{
int counter;
Button add, sub;
TextView display;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAddOne);
sub = (Button) findViewById(R.id.bSubOne);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your total is " + counter);
}
});
}
}
Thanks in advance.
EDIT: Added layout. Thought it wasn't needed:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:layout_gravity="center"
android:textSize="45dp"
android:id="#+id/tvDisplay"/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Add 1"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/bAddOne" />
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Subtract 1"
android:layout_gravity="center"
android:textSize="20dp"
android:id="#+id/bSubOne"/>
</LinearLayout>
Edit: And the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapplication"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Ok. A quick fix is to change the name of the Activity from Main.java to MainActivity.java.
package com.example.myfirstapplication;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity{
int counter;
Button add, sub;
TextView display;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAddOne);
sub = (Button) findViewById(R.id.bSubOne);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter--;
display.setText("Your total is " + counter);
}
});
}
}
The reason is That in the AndroidManifest.xml the starting Activity is declared as MainActivity:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It is in the line that says: android:name=".MainActivity", and the
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
says that it is the starting and main activity.

Categories