 |
|
ตอนนี้ผมทำโปรเจคจบ Android ครับ
ปัญหาที่ติดอยู่ คือ Intent เปลี่ยนหน้าครับ
เริ่มแรกผมกดปุ่ม จากหน้า Main เข้ามาหน้า Note_in ได้ปกติ ครับ แต่เมื่อจะเข้าหน้า Note_in_add โดยคลิกปุ่มที่สร้างไว้หน้า Note_in แต่กลับไม่มี action ใดๆเกิดขึ้นเลยครับ
รบกวนผู้รู้ช่วยชี้แนะด้วยครับ
Main.java
import com.devdroid.payardtang.note.Note_Expense;
import com.devdroid.payardtang.note.Note_in;
import com.devdroid.payardtang.plan.Plan_Main;
import com.devdroid.payardtang.report.Report;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnIncome();
btnExpense();
btnPlan();
btnReport();
btnExit();
}
public void btnIncome() {
ImageButton btnIncome = (ImageButton) findViewById(R.id.imgBtnIncome);
btnIncome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent addIncome = new Intent(getApplicationContext(),Note_in.class);
startActivity(addIncome);
finish();
}
});
}
private void btnExpense() {
ImageButton btnExpense = (ImageButton) findViewById(R.id.imgBtnExpense);
btnExpense.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent addExpense = new Intent(getApplicationContext(),Note_Expense.class);
startActivity(addExpense);
finish();
}
});
}
private void btnPlan() {
ImageButton btnPlan = (ImageButton) findViewById(R.id.imgBtnPlan);
btnPlan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent addPlan = new Intent(getApplicationContext(),Plan_Main.class);
startActivity(addPlan);
finish();
}
});
}
private void btnReport() {
ImageButton btnReport =(ImageButton) findViewById(R.id.imgBtnReport);
btnReport.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent reportPage = new Intent(getApplicationContext(),Report.class);
startActivity(reportPage);
finish();
}
});
}
public void btnExit() {
final Context context = this ;
ImageButton btnExit = (ImageButton) findViewById(R.id.imgBtnExit);
btnExit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(Main.this,
// "ImageButton is clicked!", Toast.LENGTH_SHORT).show();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
// set title
//alertDialogBuilder.setTitle("ออกจากโปรแกรม");
// set dialog message
alertDialogBuilder
.setMessage("Do you really want to exit?")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// current activity
Main.this.finish();
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.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.main, menu);
return true;
}
}
Note_in.java
import com.devdroid.payardtang.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Note_in extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.note_in);
}
public void addIncome(){
ImageButton btnAddIncome =(ImageButton) findViewById(R.id.imgaadIncome);
btnAddIncome.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent addIncome_l2 = new Intent(Note_in.this,Note_in_add.class);
startActivity(addIncome_l2);
}
});
}
}
Note_in_add.java
import com.devdroid.payardtang.R;
import android.app.Activity;
import android.os.Bundle;
public class Note_in_add extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.note_in_add);
}
}
Tag : Android, Mobile
|
ประวัติการแก้ไข 2013-01-25 01:59:37
|
 |
 |
 |
 |
Date :
2013-01-25 01:58:23 |
By :
tumjan2029 |
View :
1405 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |