我有一個機器人程序,啓動一個意向,並傳遞值到下一個活動。我之前完成了這個工作,並且工作完美。但在這種情況下,它並沒有通過價值。我用敬酒信息來查看發生了什麼,我不知道發生了什麼。另一個問題是我在其他節目中說,intent.putextra工作的代碼Android的意圖putextra不會把我的價值
Intent i= new Intent(this,SpecialLocationDatabase.class);
的工作,但在這個節目這給了我一個錯誤:「出於故意刪除參數」,所以我不得不代碼它喜歡:
Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
我的代碼如下。有兩個主要活動和SpecialLocationDataBase:
public class Main extends Activity {
/** The activity that launches the intent and passes the value. */
TextView tv;
private SpecialLocationDatabaseHelper dbIngredientHelper=null;
private static final int ACTIVITY_CREATE=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dbIngredientHelper = new SpecialLocationDatabaseHelper(this);
dbIngredientHelper.createDatabase();
final Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
long choice=1;
Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
i.putExtra("choice", choice);
//Main.this.startActivity(i);
startActivityForResult(i, ACTIVITY_CREATE);
Toast.makeText(Main.this,
"Here is your choice " + choice + " clicked",
Toast.LENGTH_LONG).show();
}
});
final Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
long choice=2;
Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
i.putExtra("choice", choice);
Main.this.startActivity(i);
}
});
final Button button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
long choice=3;
Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
i.putExtra("choice", choice);
Main.this.startActivity(i);
}
});
final Button button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
long choice=4;
Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
i.putExtra("choice", choice);
Main.this.startActivity(i);
}
});
public class SpecialLocationDatabase extends ListActivity {
/** The activity that is supposed to get the value. */
private static final int ACTIVITY_CREATE=0;
private static final int ACTIVITY_EDIT=1;
private SpecialLocationDatabaseHelper mDbHelper=null;
long choice;
private static final int BEGIN_SEARCH_OPTION = Menu.FIRST;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.specialloction);
mDbHelper=new SpecialLocationDatabaseHelper(this);
mDbHelper.openRead();
Bundle extras = getIntent().getExtras();
choice = extras.getInt("choice");
Toast.makeText(SpecialLocationDatabase.this,
"NOw your choice " + choice + " clicked",
Toast.LENGTH_LONG).show();
fillData(choice);
registerForContextMenu(getListView());
ListView list = getListView();
list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
return true;
}
});
它的工作!謝謝! – codenamejupiterx 2012-03-11 02:59:06