Android 提示框 toast AlertDialog
2010-04-09 05:46:00 来源:WEB开发网//带图标的menu
menu.add(0, ITEM_2_ID, 1, “item-2″).setIcon(R.drawable.editbills2);
menu.add(0, ITEM_3_ID, 2, “item-3″).setIcon(R.drawable.billsum1);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case 1:
Toast.makeText(this, “menu1″,Toast.LENGTH_SHORT).show();
return true;
case 2:
return true;
case 3:
return true;
}
return false;
}
4.Activity 的切换
2个Activity 的切换,没有数据传递
//从A到B
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivity(intent);
2个Activity 之间传递数据
相关的几个函数
startActivityForResult
public final void setResult(int resultCode, String data)
回调函数
protected void onActivityResult(int requestCode, int resultCode, Intent data)
例如A到B,从B得到数据
//A到B
static final int RG_REQUEST = 0;
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivityForResult(intent,RG_REQUEST);
//在B中处理
Bundle bundle = new Bundle();
bundle.putString(“DataKey”, edittext.getText().toString());//给bundle 写入数据
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
//最后在A的回调函数里面接收数据
if (requestCode == RG_REQUEST) {
if (resultCode == RESULT_CANCELED)
setTitle(“Canceled…”);
else if(resultCode == RESULT_OK) {
setTitle((String)data.getCharSequenceExtra(“DataKey”));
}
}
更多精彩
赞助商链接