|
|
|
Android สอบถามปัญหาการใช้ Intent ครับ เนื่องจากบางหน้ากดเปลี่ยนหน้าไม่ได้ครับ |
|
|
|
|
|
|
|
ตอนนี้ผมทำโปรเจคจบ 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 :
1328 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ประกาศแล้วครับ
ดังนี้ครับ
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.devdroid.payardtang"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.devdroid.payardtang.Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.devdroid.payardtang.note.Note_in"
android:label="Income"> </activity>
<activity
android:name="com.devdroid.payardtang.note.Note_in_add"
android:label="Income"> </activity>
<activity
android:name="com.devdroid.payardtang.note.Note_Expense"
android:label="Expense"> </activity>
<activity
android:name="com.devdroid.payardtang.plan.Plan_Main"
android:label="Plan"> </activity>
<activity
android:name="com.devdroid.payardtang.report.Report"
android:label="Report"> </activity>
</application>
</manifest>
|
|
|
|
|
Date :
2013-01-25 15:29:32 |
By :
tumjan2029 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ส่งไฟล์มาให้ดูหน่อย
|
|
|
|
|
Date :
2013-01-26 23:50:14 |
By :
man |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ ผมลืมเอา method ไปใส่ใน oncreate ครับ
|
|
|
|
|
Date :
2013-01-27 14:40:46 |
By :
tumjan2029 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-01-28 20:24:21 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|