Android Bundle.putInt(),它是如何工作的?
我仍然在学习android,我在一个教程中学习Android Bundle.putInt(),它是如何工作的?,android,Android,我仍然在学习android,我在一个教程中学习 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub int id_To_Search = arg2 + 1; Bundle dataBundle = new Bundle(); d
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
int id_To_Search = arg2 + 1;
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getApplicationContext(),com.example.addressbook.DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
}
});
如果id\u To\u Search=0,那么id=0?id是指列名吗
安卓网站解释
putInt(String key, int value)
Inserts an int value into the mapping of this Bundle, replacing any existing value for the given key.
据我所知,如果int=5,那么键将是5?
然后“Id”将是=5?1)您可以与其他类似活动共享int
:
String YOUR_KEY = "id";
Intent intent = new Intent(getApplicationContext(), DisplayContact.class);
intent.putExtra(YOUR_KEY, id);
startActivity(intent);
int defaultValue = 0;
int id = getIntent().getIntExtra(YOUR_KEY, defaultValue);
或
2)并在您的活动中获得int
:
String YOUR_KEY = "id";
Intent intent = new Intent(getApplicationContext(), DisplayContact.class);
intent.putExtra(YOUR_KEY, id);
startActivity(intent);
int defaultValue = 0;
int id = getIntent().getIntExtra(YOUR_KEY, defaultValue);
或
那正是你说的 据我所知,如果int=5,那么键将是5?那么“Id”将是=5 所以,当你进入另一个活动时,这里
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getApplicationContext(),com.example.addressbook.DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
您可以执行
intid=getIntent().getIntExtra(“id”)代码>,将是5是的,我理解意图是如何工作的,我是说关于bundle.putinentent包含bundle,它是一样的!举例说明我的答案
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getApplicationContext(),com.example.addressbook.DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);