Monday, April 8, 2013

[android help] How do I use intend to change the Activites?


I made some buttons and i want to change to another activity when that button1 is clicked. but it won't find my viewImave.class


I'm


This is my 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");
benter code hereutton2.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();
}
}


}


This is my 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();
}
}


This is showimage.xml




android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/koala" />




This is activity_main.xml



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

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"
/>

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" />




.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...