As mentioned in title, I face an error when I compile and try to run the following program in my phone.
Code:
(File mainActivity.java)
package com.game.myapp;
import android.app.*;
import android.os.*;
import android.content.Intent;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void VillageOnClick() {
Intent intent = new Intent(MainActivity.this, VillageView.class);
startActivity(intent);
}
}
(File VillageView.java)
package com.game.myapp;
import android.app.*;
import android.os.*;
public class VillageView extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.village_view);
}
}
(File main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_gravity="bottom">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="village"
android:onClick="VillageOnClick"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="research"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="battle"/>
</LinearLayout>
</LinearLayout>
(File village_view.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="fill_parent"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_margin="10dp">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button"/>
</LinearLayout>
</LinearLayout>
Note:I write, compile, install and run the app on my android phone only using an app.
Note2: both the xml files are located in res/layout and most probable are not the cause of the error.
Note3: I do not understand Intent. Knowledge about the same is always appreciated.
Thanks in advance.
PS. Suggestions and change in format of code is always accepted happily.
Madworks.
you need to add the View in the VillageOnClick
public void VillageOnClick(View v) {
Intent intent = new Intent(MainActivity.this, VillageView.class);
startActivity(intent);
}
Related
I am a beginner to android. I want to slide a slidebar in a horizontal linear layout but when I run the code, the application ends giving error FallingBall keeps stopping
My xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
android:weightSum="100"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="72"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:orientation="horizontal">
<ImageView
android:id="#+id/slideBar"
android:layout_width="100dp"
android:layout_height="match_parent"
app:srcCompat="#android:drawable/bottom_bar" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:orientation="horizontal">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/leftBut"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/left_but"
android:onClick="hitLeft"/>
<ImageButton
android:id="#+id/rightBut"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/right_but"
android:onClick="hitRight"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
My java file is like this:
package com.example.fallingball;
import androidx.appcompat.app.AppCompatActivity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView s = findViewById(R.id.slideBar);
float x = s.getX();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
void hitLeft(View view){
x--;
s.setX(30);
}
void hitRight(View view){
x++;
s.setX(40);
}
}
Note: leftBut and rightBut are two Image button and I have copied the images to the drawable folder so if you are trying this code on your system, make sure you adjust this else it will show you Image not found or so...
In MainActivity.java you should initialize your value into onCreate() method
ImageView s;
float x;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
s = findViewById(R.id.slideBar);
x = s.getX();
}
Well, I found my own mistake. The thing what hossein answered earlier was right but the application was still crashing. Actually the problem was coming that I was triggering the methods hitLeft and hitRight which were not initialized as public. That was the mistake and now it is working alright...
How do you change the calendar layout to vertical mode?
I am using CalendarView within ScrollView. Now I am implementing the scroll up and down view in Vertical scroll for getting previous or next months calendar.
I am trying to implement like below CalendarView.....
https://ibb.co/TLDFbrm "CalendarView Like that"
Please help me I am in trouble.
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<CalendarView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
</CalendarView>
</LinearLayout>
</ScrollView>
Any ideas? Let me know! thanks...
Follow the below code.
Activity_main.xml code
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="ganeshannt.calendarview.MainActivity">
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="51dp"
android:text="Date"
android:textAlignment="center"
android:textSize="45dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.219" />
<Button
android:id="#+id/btngocalendar"
android:layout_width="266dp"
android:layout_height="47dp"
android:text="Go to calendar"
tools:layout_editor_absoluteX="47dp"
tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>
Create new calendar_layout.xml file (File ⇒ New ⇒Activity⇒Empty_activity).
Go to calendar_layout.xml then click the text bottom.
This xml file contains the designing code for android app,Into the calendar_layout.xml copy and paste the below code
calendar_layout.xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<CalendarView
android:id="#+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Create new CalendarActivity.java file (File ⇒ New ⇒Java class).
Into the CalendarActivity.java copy and paste the below code.java programming is the backend language for android. Do not replace your package name otherwise app will not run.
CalendarActivity.java code
package ganeshannt.calendarview;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.CalendarView;
public class CalendarActivity extends AppCompatActivity {
private static final String TAG = "CalendarActivity";
private CalendarView mCalendarView;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar_layout);
mCalendarView = (CalendarView) findViewById(R.id.calendarView);
mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
#Override
public void onSelectedDayChange(CalendarView CalendarView, int year, int month, int dayOfMonth) {
String date = year + "/" + month + "/"+ dayOfMonth ;
Log.d(TAG, "onSelectedDayChange: yyyy/mm/dd:" + date);
Intent intent = new Intent(CalendarActivity.this,MainActivity.class);
intent.putExtra("date",date);
startActivity(intent);
}
});
}
}
My 1st Activity java file source code is not working the way I want. I can not seem to get the animation to run at the start of my 1st activity. I can only get it to run after the 2nd Java Activity by physically going back to the 1st activity by hard pressing back on the Android keyboard.
package com.demotxt.droidsrce.welcomescreen;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
public class WelcomeActivity extends AppCompatActivity {
LinearLayout l1, l2;
Button btnsub;
Animation uptodown, downtoup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
btnsub = (Button) findViewById(R.id.buttonsub);
btnsub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
NextActivity();
}
});
}
public void NextActivity() {
Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
l1 = (LinearLayout) findViewById(R.id.l1);
l2 = (LinearLayout) findViewById(R.id.l2);
uptodown = AnimationUtils.loadAnimation(this, R.anim.uptodown);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
l1.setAnimation(uptodown);
l2.setAnimation(downtoup);
}
}
This is my XML File for the 1st Activity and everything here is also running smoothly, but I have the same problem. There seems to be an issue running the java and XML script backward and forward to run the animation both ways.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="com.demotxt.droidsrce.welcomescreen.WelcomeActivity"
android:orientation="vertical"
android:background="#drawable/background">
<LinearLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="25dp"
android:text="Welcome to"
android:textColor="#color/lightorange"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_width="398dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:text=" BLUEY AUSTRALIA"
android:textAlignment="textStart"
android:textColor="#android:color/holo_blue_light"
android:textColorHighlight="#android:color/holo_blue_bright"
android:textColorHint="#android:color/holo_blue_bright"
android:textColorLink="#android:color/holo_blue_bright"
android:textSize="30sp" />
<ImageView
android:id="#+id/Bluey_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/bluey_logo" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/l2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#drawable/spaceullustration"
android:orientation="vertical">
<Button
android:id="#+id/buttonsub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/buttonstyle"
android:text="JOIN BLUEY"
android:textColor="#color/bluey"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
try change the order
l1 = (LinearLayout) findViewById(R.id.l1);
l2 = (LinearLayout) findViewById(R.id.l2);
uptodown = AnimationUtils.loadAnimation(this, R.anim.uptodown);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
l1.setAnimation(uptodown);
l2.setAnimation(downtoup);
startActivity(intent); //<<<<<<<<<<<<<<,
It is not a clean and rebuild issue AT ALL! Make module will not
resolve this issue either. This is the only
FlotingActionButton I'm using in my code. One solution said this only
occurs with an anchor parameter but as you can see I am not using one
so I dont know what to make of it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:id="#+id/activity_main"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/coverpic"
tools:context="com.android.nohiccupsbeta.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/effects_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="top|end"
android:layout_marginTop="400dp"
android:layout_marginRight="15dp"
android:src="#drawable/ic_book"
app:backgroundTint="#color/primary_color" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/take_test"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:backgroundTint="#color/primary_color"
android:src="#drawable/ic_handcuffs" />
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
This is the JAVA code. I tried importing the Coordinator Layout but
that is not possible. I also tried declaring the fab var differently
just to get the same error :
package com.android.nohiccupsbeta;
import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, pageone.class));
}
});
FloatingActionButton fab2 = (FloatingActionButton)findViewById(R.id.fab2);
fab2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, BacTest.class));
}
});
}
}
Your second FloatingActionButton does not have an id, and the one you are trying to cast into a FAB is the CoordinatorLayout.
So, you should set an id in your layout for your fabs like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:id="#+id/activity_main"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/coverpic">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/effects_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="top|end"
android:layout_marginTop="400dp"
android:layout_marginRight="15dp"
android:src="#drawable/ic_book"
app:backgroundTint="#color/primary_color" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/take_test"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:backgroundTint="#color/primary_color"
android:src="#drawable/ic_handcuffs" />
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
and your fabs to match the new ids like this
FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
FloatingActionButton fab2 = (FloatingActionButton)findViewById(R.id.fab2);
I have a page that has a button, when you click it, it goes to another page with another button, when I click the button that takes to third page, it doesn't! I tried to make MainActive2.java and PageOne2.java but it didn't work! Help!
active_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#1d72c3"
android:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:orientation="vertical"
android:textStyle="italic" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/abus"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="About us"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="italic" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
abus.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="fill_parent"
android:layout_height="fill_parent"
android:background="#1d72c3"
android:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textStyle="italic"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/abus2"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="About us"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="italic" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
abus2.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="fill_parent"
android:layout_height="fill_parent"
android:background="#1d72c3"
android:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textStyle="italic"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textStyle="italic"
android:textColor="#ffffff"
android:textSize="18sp"
android:text="Hello" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
MainActivity.java
package com.d.da;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button button1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button1 = (Button) findViewById(R.id.abus);
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, PageOne.class);
startActivity(intent);
}
});
}
}
PageOne.java
package com.d.da;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class PageOne extends Activity {
Button button1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abus);
}
}
You didn't add OnClickListener to a button on second activity
EDIT:
package com.d.da;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class PageOne extends Activity {
Button button2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abus);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button2 = (Button) findViewById(R.id.abus2);
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, MainActivity2.class);
startActivity(intent);
}
});
}
}
public class PageOne extends Activity {
Button button1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abus);
button1 = (Button) findViewById(R.id.abus2);
button1.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
//do things here
Intent intent = new Intent(PageOne.this, OtherActivity.class);
PageOne.this.startActivity(intent);
}
});
}
}
Also, you honestly should use some more descriptive IDs. You ARE going to have access to them throughout the application via the R resource class, which means having abus1 abus2 abus3 abus4 abus5 in your activities will eventually get extremely confusing.