Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Bundle.putInt(),它是如何工作的?_Android - Fatal编程技术网

Android Bundle.putInt(),它是如何工作的?

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

我仍然在学习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();
         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);