I have an ImageButton that when I want it to be pressed to launch a second Activity. The second activity is called "Dust 2" as seen in my android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pete.smokesapp" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".homepage"
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=".Dust2"
android:label="#string/title_activity_dust2" >
</activity>
</application>
</manifest>
I tried following a guide online but got me as far as this stage now my app crashed on launch.
package pete.smokesapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
public class homepage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
findViewById(R.id.imgDust2).setOnClickListener((View.OnClickListener) this);
}
public void imgDust2(View view) {
switch (view.getId()){
case R.id.imgDust2:
Toast.makeText(this, "Dust 2 Clicked", Toast.LENGTH_LONG ).show();
break;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_homepage, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Here is also my main activity, this is the activity with the ImageButton, i am also new to this so sorry if I seem clueless.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Maps"
android:id="#+id/txtMaps"
android:layout_weight="0.44" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgDust2"
android:clickable="false"
android:src="#drawable/dust2"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgInferno"
android:layout_below="#+id/txtOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp"
android:src="#drawable/inferno" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgOverpass"
android:src="#drawable/overpass"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgMirage"
android:clickable="false"
android:src="#drawable/mirage"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgCache"
android:clickable="false"
android:src="#drawable/cache"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgNuke"
android:clickable="false"
android:src="#drawable/nuke"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
There are two methods available in android using which you can go from one Activity to another.
1. Use button.setOnClickListener()
Create a button in xml file.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Now set event listener for the button in your .class file
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//set the event you want to perform when button is clicked
//you can go to another activity in your app by creating Intent
Intent intent = new Intent(getApplicationContext, Activity2.class);
startActivity(intent);
}
});
2. Use <android:onClick="goNext">
Put the onClick as the attribute of the button you have created in xml file.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="goNext" />
Now in your .class file define an event for that button as,
goNext() {
Intent intent = new Intent(getApplicationContext, Activity2.class);
startActivity(intent);
}
In your first activity do this:
Button button = (Button) findViewById(R.id.imgDust2);
button.setOnClickListener(new View.OnClickListener () {
#Override
public void onClick(View v){
Intent intent = new Intent(v.getContext(), dust2.class);
startActivity(intent);
}
});
Try the following:
Add implements OnClickListener to your class definition: public class homepage extends ActionBarActivity implements OnClickListener
An error will appear and ask you to add unimplemented methods. Do so.
Change findViewById(R.id.imgDust2).setOnClickListener((View.OnClickListener) this); to findViewById(R.id.imgDust2).setOnClickListener(this);
Place the stuff you want to do when the button is clicked into the new method that was added in step 2.
Set onClick to the xml imageView and put the name of the method:
<ImageButton
android:layout_width="350dp"
android:layout_height="150dp"
android:id="#+id/imgDust2"
android:clickable="false"
android:src="#drawable/dust2"
android:layout_above="#+id/imgOverpass"
android:layout_alignLeft="#+id/imgOverpass"
android:layout_alignStart="#+id/imgOverpass"
android:layout_marginBottom="10dp"
android:onClick="imgDust2"/>
Related
I have been trying to implement splash Screen to my app with help of many codes avaible in sites , but none worked for me.
Each time the app is crashing after displaying splash screen for 3 secs.
I don't know where i'm going wrong , please make corrections to my code to display splash screen correctly ! Thank You !
//This is my Main activity
1. public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button one = (Button) this.findViewById(R.id.gg);
final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.gg);
one.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Good Game", Toast.LENGTH_SHORT).show();
mp1.start();
}
});
Button two = (Button) this.findViewById(R.id.gm);
final MediaPlayer mp2 = MediaPlayer.create(this, R.raw.gm);
two.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Oh, They got me!", Toast.LENGTH_SHORT).show();
mp2.start();
}
});
Button three = (Button) this.findViewById(R.id.cb);
final MediaPlayer mp3 = MediaPlayer.create(this, R.raw.cb);
three.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Come on boy", Toast.LENGTH_SHORT).show();
mp3.start();
}
});
Button four = (Button) this.findViewById(R.id.ns);
final MediaPlayer mp4 = MediaPlayer.create(this, R.raw.ns);
four.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Nice shot", Toast.LENGTH_SHORT).show();
mp4.start();
}
});
Button five = (Button) this.findViewById(R.id.wp);
final MediaPlayer mp5 = MediaPlayer.create(this, R.raw.wp);
five.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "You wanna piece of me!", Toast.LENGTH_SHORT).show();
mp5.start();
}
});
Button six = (Button) this.findViewById(R.id.bi);
final MediaPlayer mp6 = MediaPlayer.create(this, R.raw.bi);
six.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Bring it", Toast.LENGTH_SHORT).show();
mp6.start();
}
});
Button seven = (Button) this.findViewById(R.id.lg);
final MediaPlayer mp7 = MediaPlayer.create(this, R.raw.lg);
seven.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Let’s go, Yeah!", Toast.LENGTH_SHORT).show();
mp7.start();
}
});
Button eight = (Button) this.findViewById(R.id.ru);
final MediaPlayer mp8 = MediaPlayer.create(this, R.raw.ru);
eight.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Ready Up", Toast.LENGTH_SHORT).show();
mp8.start();
}
});
Button nine = (Button) this.findViewById(R.id.nn);
final MediaPlayer mp9 = MediaPlayer.create(this, R.raw.nn);
nine.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Nooooo", Toast.LENGTH_SHORT).show();
mp9.start();
}
});
Button ten = (Button) this.findViewById(R.id.cm);
final MediaPlayer mp10 = MediaPlayer.create(this, R.raw.cm);
ten.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Cover me", Toast.LENGTH_SHORT).show();
mp10.start();
}
});
Button eleven = (Button) this.findViewById(R.id.hh);
final MediaPlayer mp11 = MediaPlayer.create(this, R.raw.hh);
eleven.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Hoo-ya", Toast.LENGTH_SHORT).show();
mp11.start();
}
});
Button twelve = (Button) this.findViewById(R.id.mo);
final MediaPlayer mp12 = MediaPlayer.create(this, R.raw.mo);
twelve.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Move out", Toast.LENGTH_SHORT).show();
mp12.start();
}
});
Button thirteen = (Button) this.findViewById(R.id.gs);
final MediaPlayer mp13 = MediaPlayer.create(this, R.raw.gs);
thirteen.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Get Some", Toast.LENGTH_SHORT).show();
mp13.start();
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Your Messege",Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//This is my activity_main.xml
2. <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.android.mmm.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
//This is content_main.xml
3. <android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.android.mmm.MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000">
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="GG"
android:id="#+id/gg"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/gm"
android:layout_width="100dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:text="GM"
android:textAllCaps="true"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="CB"
android:id="#+id/cb"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="NS"
android:id="#+id/ns"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="WP"
android:id="#+id/wp"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="BI"
android:id="#+id/bi"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="LG"
android:id="#+id/lg"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="RU"
android:id="#+id/ru"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="NN"
android:id="#+id/nn"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="CM"
android:id="#+id/cm"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="HH"
android:id="#+id/hh"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="MO"
android:id="#+id/mo"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="100dp"
android:layout_height="48dp"
android:text="GS"
android:id="#+id/gs"
android:textSize="18sp"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
tools:ignore="HardcodedText"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
//This is AndroidManifest.xml
4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.mmm">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
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=".MainActivity"
android:label="#string/app_name" >
</activity>
</application>
//This is styles.xml
5. <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" />
</resources>
//This is my SplashActivity.Java
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);
}
}
6. //This is activity_splash.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/wwe_logo" />
</RelativeLayout>
AppCompatActivity has it's own toolbar so you need to remove it by using android:theme="#style/AppTheme.NoActionBar" in manifest
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
Although if you are not doing much customization in your toolbar then your can also skip creating your own toolbar by removing it from XML and removing it's initialization from java code as well but by doing this , you will lose the feature of collapsing toolbar
Making a splash screen is actually pretty easy.
1. Create drawable
In my case, I created a drawable named splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorWhite" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/sensesmart_icon" />
</item>
2. Add drawable to your styles.xml
Here I just added my drawable to styles:
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/splash</item>
</style>
3. Add splash to manifest
You want to actually tell your app that the splash layout should show before the app has loaded:
<activity android:name=".BaseActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme"> <!--Splash screen-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
4. Set theme on your starting activity
In my case, BaseActivity is the activity which starts my application, so inside my onCreate(), I start with setting my theme:
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_base);
super.onCreate(savedInstanceState);
}
This is the only thing you need to do. If you use this method, the splash screen doesn't stay for longer than it needs. Your contentView will start as soon as you have loaded your app.
Hope this helps!
I am building this application on android studio and i am trying to link my button with next activity which is login screen. before i had it working with register screen but then i messed up with code now it just doesn't work when i run the application and click on register button my app crashes and shuts down and login button doesn't even do anything.
below is the code for main page activity and login page activity
first i will paste frontpage activity code where the button is, then its java class, then i will paste loginpage activity and then its java class.
can someone pls advice me how to call the login activity from the login button on the front page.
thank you so much in advance
frontpage activity
<?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"
tools:context=".Login">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#drawable/bg3"
android:gravity="center|top">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Easy Booking"
android:id="#+id/textView"
android:textSize="33dp"
android:gravity="center"
android:textColor="#0c0c0c"
/>
<Button
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:id="#+id/btLogin"
android:onClick="bLogin"
android:background="#null"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="108dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Register"
android:id="#+id/btRegister"
android:onClick="bRegister"
android:background="#null"
android:layout_gravity="center_horizontal" />
</LinearLayout>
now its java class
public class Frontpage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frontpage);
//OnclickButtonListener();
}
public void bLogin(View view) {
}
public void onButtonClick(View v){
if (v.getId() == R.id.btRegister) {
Intent i = new Intent(new Intent(Frontpage.this, Register.class));
startActivity(i);
}
}
/**
public void OnclickButtonListener(){
button = (Button)findViewById(R.id.bRegister);
button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("/Users/umairfarooq/AndroidStudioProjects/Easybooking/app/src/main/res/layo ut/activity_register");
startActivity(intent);
}
}
);
} /**#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity_login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
*/}
below is the login activity
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#635b5b"
android:orientation="vertical"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Form"
android:textAppearance="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Email"
android:id="#+id/etUsername"
android:layout_gravity="center_horizontal"
android:layout_marginTop="70dp"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Password"
android:id="#+id/etPassword"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:inputType="textPassword"
/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:onClick="userLogin"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Now"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="userReg"
/>
</LinearLayout>
and now login java class
package com.example.umairfarooq.easybooking;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
public class Login extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void buttonOnClick (View v){
}
}
The problem is that your activities don't contain the methods that you've set for your buttons' android:onClick attribute.
For the layout that the Frontpage activity is using, you can either change btRegister button's android:onClick attribute to android:onClick="onButtonClick" or create a public void bRegister(View v){...} method in that activity.
For the Login activity, the layout has two buttons with their android:onClick attribute set to userReg and userLogin, you can either create those methods in the activity or change both of those attributes values to buttonOnClick.
when i run the application and click on register button my app crashes
and shuts down
It is because this button:
<Button
android:layout_width="108dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Register"
android:id="#+id/btRegister"
android:onClick="bRegister"
android:background="#null"
android:layout_gravity="center_horizontal" />
in your frontpage activity needs a method with signature public void bRegister(View view) in your FrontPage.java class. As you do not have this method, it crashes.
login button doesn't even do anything
The reason is, this button
<Button
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:id="#+id/btLogin"
android:onClick="bLogin"
android:background="#null"
android:layout_gravity="center_horizontal" />
in your frontpage activity needs a method called public void bLogin(View view) in your Frontpage.java class. Though the method is present, you do not have any code in it, hence it does not do anything.
You need to add proper code in bLogin method so that your login button starts functioning, and even before that add a bRegister method so that your register button starts working.
Hope this helps you.
When I run the analize it on comes back with one error in the manafest android name = is not public
but when i build it says built with no error but when i run it on my emu and my tablet it crashes i can not figure this out please help. This is my code with names omitted.
activity_main.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.xxxx.xxxx.app.MainActivity"
android:background="#drawable/appbackground">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/facebook"
android:id="#+id/button1"
android:background="#drawable/facebook"
android:clickable="true"
android:enabled="true"
android:gravity="end"
android:width="50dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/button3"
android:layout_alignEnd="#+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dealer"
android:id="#+id/button2"
android:enabled="true"
android:background="#drawable/dealer"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/button4"
android:layout_alignStart="#+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/map"
android:id="#+id/button3"
android:enabled="true"
android:clickable="true"
android:background="#drawable/google_navigation"
android:layout_below="#+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="29dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about"
android:id="#+id/button4"
android:enabled="true"
android:clickable="true"
android:background="#drawable/about"
android:layout_alignBottom="#+id/button3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pthdh"
android:id="#+id/button5"
android:layout_below="#+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:enabled="true"
android:clickable="true"
android:background="#drawable/pthdh" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rpe"
android:id="#+id/button6"
android:layout_alignTop="#+id/button5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:enabled="true"
android:clickable="true"
android:background="#drawable/rpebutton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/call"
android:id="#+id/button7"
android:enabled="true"
android:clickable="true"
android:background="#drawable/callus"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/contact"
android:id="#+id/button8"
android:enabled="true"
android:clickable="true"
android:background="#drawable/contact"
android:layout_marginBottom="31dp"
android:layout_above="#+id/button7"
android:layout_centerHorizontal="true" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textClock"
android:textStyle="bold"
android:textColor="#000000"
android:background="#ff5300"
android:gravity="center"
android:textSize="30sp"
android:textIsSelectable="true"
android:layout_above="#+id/button8"
android:layout_alignLeft="#+id/button8"
android:layout_alignStart="#+id/button8"
android:layout_marginBottom="34dp" />
</RelativeLayout>
MainActivity.java
package com.xxxx.xxxx.app;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
class MainActivity extends Activity implements OnClickListener{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);
Button button4 = (Button) findViewById(R.id.button4);
Button button5 = (Button) findViewById(R.id.button5);
Button button6 = (Button) findViewById(R.id.button6);
Button button7 = (Button) findViewById(R.id.button7);
Button button8 = (Button) findViewById(R.id.button8);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
button5.setOnClickListener(this);
button6.setOnClickListener(this);
button7.setOnClickListener(this);
button8.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana",
"com.facebook.katana.ProfileTabHostActivity");
Long uid = new Long("xxxx");
intent.putExtra("extra_user_id", uid);
startActivity(intent);
break;
case R.id.button2:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com"));
startActivity(intent);
break;
case R.id.button3:
Uri location = Uri.parse("geo:xx.xxx7629,-xx.xxxx584?z=14");
new Intent(Intent.ACTION_VIEW, location);
break;
case R.id.button4:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com/default.asp?page=info"));
startActivity(intent);
break;
case R.id.button5:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com/"));
startActivity(intent);
break;
case R.id.button6:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("https://members.xxxx.com/"));
startActivity(intent);
break;
case R.id.button7:
Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:xxxx"));
startActivity(dial);
break;
case R.id.button8:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse
("http://www.xxxx.com/default.asp?page=xcontact"));
startActivity(intent);
break;
default:
Log.d(getApplication().getPackageName(), "Button click error!");
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
}
AndroidManifest xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxx.xxxx.app" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.xxxx.xxxx.app.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
You have to put "public" before "class":
public class MainActivity extends Activity implements OnClickListener
I have this problem that just seems strange.
I have this Android View with six buttons and when i click on one of them(the only one with the action defined apart from the exit button), it gives me a RuntimeError.
The Activity is declared on the manifest, and this is why i don't understand my error.
Can someone please help me with this.
I would really appreciate it :)
So here's my code:
package com.example.calendar;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View createButton = findViewById(R.id.btn_create);
View deleteButton = findViewById(R.id.btn_delete);
View moveButton = findViewById(R.id.btn_move);
View searchButton = findViewById(R.id.btn_search);
View translateButton = findViewById(R.id.btn_translate);
View exitButton = findViewById(R.id.exit);
createButton.setOnClickListener(this);
deleteButton.setOnClickListener(this);
moveButton.setOnClickListener(this);
searchButton.setOnClickListener(this);
translateButton.setOnClickListener(this);
exitButton.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_create:
Intent i = new Intent(this, CreateAppointment.class);
startActivity(i);
break;
case R.id.exit:
finish();
break;
}
}
}
My layout is like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/background"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="225dp"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" >
<CalendarView
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="2dip"
android:layout_marginTop="2dip"
android:stretchColumns="*" >
<TableRow>
<Button
android:id="#+id/btn_create"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/create" />
<Button
android:id="#+id/btn_viewEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/viewEdit" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/delete" />
<Button
android:id="#+id/btn_move"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/move" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/search" />
<Button
android:id="#+id/btn_translate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/translate" />
</TableRow>
</TableLayout>
<Button
android:id="#+id/exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/exit"/>
</LinearLayout>
And the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.calendar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.calendar.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=".CreateAppointment"
android:theme="#android:style/Theme.Dialog"
android:label="#string/create" >
</activity>
</application>
</manifest>
You have to define correctly what kind of views ares using in onCreate()
View createButton = findViewById(R.id.btn_create);
for example:
since you are using a Button:
<Button
android:id="#+id/btn_create"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/create" />
Make the cast as button:
Button createButton = (Button)findViewById(R.id.btn_create);
try this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button createButton = (Button)findViewById(R.id.btn_create);
Button deleteButton = (Button)findViewById(R.id.btn_delete);
Button moveButton = (Button)findViewById(R.id.btn_move);
Button searchButton = (Button)findViewById(R.id.btn_search);
Button translateButton = (Button)findViewById(R.id.btn_translate);
Button exitButton = (Button)findViewById(R.id.exit);
createButton.setOnClickListener(this);
deleteButton.setOnClickListener(this);
moveButton.setOnClickListener(this);
searchButton.setOnClickListener(this);
translateButton.setOnClickListener(this);
exitButton.setOnClickListener(this);
}
Hey i'm brand new to programming and i need some help,
i'm doing a project for school and it's an android app where the user inputs words to a text field and then those words are used to create a story, like mad libs. I can not seem to see what is wrong with my code here when i debug on my phone it just shows a white screen. Could someone point out to me what i'm doing wrong? thanks...
MainActivity.java:
package com.joe.madlibs;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
EditText Noun, Adj, Name, Verb, Verb2, Noun2, Adj2;
Button Submit;
TextView Story;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Noun = (EditText) findViewById(R.id.noun1);
Adj = (EditText) findViewById(R.id.adjective1);
Name = (EditText) findViewById(R.id.name1);
Verb = (EditText) findViewById(R.id.verb1);
Verb2 = (EditText) findViewById(R.id.verb2);
Noun2 = (EditText) findViewById(R.id.noun2);
Adj2 = (EditText) findViewById(R.id.adj2);
String noun = Noun.getText().toString();
String adj = Adj.getText().toString();
String name = Name.getText().toString();
String verb = Verb.getText().toString();
String verb2 = Verb2.getText().toString();
String noun2 = Noun2.getText().toString();
String adj2 = Adj2.getText().toString();
Submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.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=".MainActivity" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<EditText
android:id="#+id/noun1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_alignTop="#+id/linearLayout1"
android:ems="10"
android:hint="#string/noun" >
</EditText>
<EditText
android:id="#+id/verb1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/name1"
android:layout_alignBottom="#+id/name1"
android:layout_alignRight="#+id/storyBox"
android:ems="10"
android:hint="#string/verb" />
<EditText
android:id="#+id/adjective1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/noun1"
android:layout_alignBottom="#+id/noun1"
android:layout_alignLeft="#+id/verb1"
android:ems="10"
android:hint="#string/adjective" />
<EditText
android:id="#+id/name1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/noun1"
android:layout_below="#+id/noun1"
android:ems="10"
android:hint="#string/name" />
<EditText
android:id="#+id/verb2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name1"
android:layout_below="#+id/name1"
android:ems="10"
android:hint="#string/verb" />
<EditText
android:id="#+id/adj2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/verb1"
android:layout_below="#+id/verb1"
android:ems="10"
android:hint="Adjective" />
<EditText
android:id="#+id/noun2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/verb2"
android:layout_below="#+id/verb2"
android:ems="10"
android:hint="Noun" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Click here to get your story!" />
<TextView
android:id="#+id/storyBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/noun2"
android:layout_below="#+id/button1"
android:layout_marginTop="18dp"
android:text="This is where your story will go!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Joe.madlibs"
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.Joe.madlibs.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>
</application>
</manifest>
Umm... where are you instantiating your Submit button before trying to set an onClickListener on it? I see where you declare it, but you aren't instantiating it.
Add:
Submit = (Button)findViewById(R.id.button1);
right before
Submit.setOnClickListener(new View.OnClickListener() {
and watch. It's gonna be like magic.
One more thing about coding conventions (style): when you name your instance variables, use the headlessCamelCase convention. Names with CamelCase/InitCaps (first letter of each word capitalized) should only be used when you name your class (the pattern for an object) as opposed to when you refer to an instance of that class (the actual object).
Wrong:
// An instance of Button class
Button Submit;
Right:
// An instance of Button class:
Button submit;
When it comes to compound names (more than one word), headlessCamelCase means you capitalize the first letter of each word, except the first word.
Right:
// An instance of Button class:
Button myVeryElderlyMotherJustSatUponNapoleonsSubmitButton;