I am trying to create 8 buttons in one activity that will open their own activity. What am I missing? I am using Android Studio 1.1.0.
I get this error
java.lang.IllegalStateException:
Could not find a method AppleActivity(View) in the activity class
com.hashmi.omar.vodafonemobilephoneshop.Picker for onClick handler
on view class android.widget.Button with id 'button2'
Below is the Picker.class:
package com.hashmi.omar.vodafonemobilephoneshop;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.hashmi.omar.vodafonemobilephoneshop.util.SamsungActivity;
public class Picker extends Activity implements View.OnClickListener {
Button button2, button3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picker);
//Sets the font to Vodafone Light
Typeface vodaLt = Typeface.createFromAsset(getAssets(), "VODAFONELT.TTF");
TextView vodaHeading = (TextView)findViewById(R.id.textView4);
vodaHeading.setTypeface(vodaLt);
//Sets up a button
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(this);
}
private void buttonapple(){
startActivity(new Intent(Picker.this, AppleActivity.class));
}
private void buttonsam(){
startActivity(new Intent(Picker.this, SamsungActivity.class));
}
public void onClick(View v) {
switch (v.getId())
{
case R.id.button2:
buttonapple();
break;
case R.id.button3:
buttonsam();
break;
}
}
}
Below is the activity_picker.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.hashmi.omar.vodafonemobilephoneshop.Picker"
android:background="#ffffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Please choose a brand"
android:id="@+id/textView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#ffff0000"
android:textSize="31dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/appsel"
android:id="@+id/button2"
android:layout_column="0"
android:onClick="@string/title_activity_apple" />
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/samselect"
android:id="@+id/button3"
android:layout_column="20"
android:onClick="@string/title_activity_samsung" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/sonyselect"
android:id="@+id/button4"
android:layout_column="0" />
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/htcselect"
android:id="@+id/button5"
android:layout_column="20" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/bbselect"
android:id="@+id/button6"
android:layout_column="0" />
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/nokiaselect"
android:id="@+id/button7"
android:layout_column="20" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/nexselect"
android:id="@+id/button8"
android:layout_column="0" />
<Button
android:layout_width="160dp"
android:layout_height="125dp"
android:background="@drawable/lgselect"
android:id="@+id/button9"
android:layout_column="20" />
</TableRow>
</TableLayout>
Here is AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".HomeScreen"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Picker"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.hashmi.omar.vodafonemobilephoneshop.Picker" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AppleActivity"
android:label="@string/title_activity_apple"
android:parentActivityName=".Picker" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.hashmi.omar.vodafonemobilephoneshop.Picker" />
<action android:name="com.hashmi.omar.vodafonemobilephoneshop.AppleActivity" />
</activity>
<activity
android:name=".SamsungActivity"
android:label="@string/title_activity_samsung"
android:parentActivityName=".Picker" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.hashmi.omar.vodafonemobilephoneshop.Picker" />
</activity>
<activity
android:name=".util.SamsungActivity"
android:label="@string/title_activity_samsung"
android:parentActivityName=".Picker" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.hashmi.omar.vodafonemobilephoneshop.Picker" />
</activity>
</application>