我做了一些按钮,我想在单击该 button1 时更改为另一个活动。但它不会找到我的 viewImave.class
我是
这是我的 MainActivity.java
package com.example.image;
import android.os.Bundle;
import android.view.View.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnClickListener {
Toast toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button1 = (Button)findViewById(R.id.button1);
button1.setText("take Image");
button1.setOnClickListener(this);
final Button button2 = (Button)findViewById(R.id.button2);
button2 = (Button)findViewById(R.id.button2);
button2.setText("take Image2");
button2.setOnClickListener(this);
}
@Override
public void onClick (View v) {
if(v.getId()==R.id.button1){
Intent showimageIntent = new Intent(this, ViewImave.class);
startActivity(showimageIntent);
}
else if(v.getId()==R.id.button2)
{
toast = Toast.makeText(this, "onclickbutton2", Toast.LENGTH_SHORT);
toast.show();
}
else
{
toast = Toast.makeText(this, "error", Toast.LENGTH_SHORT);
toast.show();
}
}
}
这是我的 ViewImave.java
package com.example.image;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import android.app.Activity;
import android.view.Menu;
public class ViewImave extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {//
setContentView(R.layout.showimage);
Toast toast = Toast.makeText(this, "newimage oncreate", Toast.LENGTH_SHORT);
toast.show();
}
}
这是 showimage.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:orientation="vertical" >
<Showimage
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/koala" />
</LinearLayout>
这是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"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1"
android:text="Button" />
</RelativeLayout>