我的程序應將編輯文本中識別的電話號碼和電子郵件的值傳遞給另一個活動,該活動分別包含電話號碼和電子郵件的edittext。 我已經設法通過電話號碼和電子郵件的價值逐一。但我失敗時,試圖通過他們在同一時間。用於傳遞多個數據的一個按鈕
\t public void onClickbutton2(View v)
\t {
\t \t /*----------------------------------phone number catcher------------------*/
\t
\t \t String text = _field.getText().toString();
\t \t Pattern pt = Pattern.compile("\\d{5,11}");
\t \t Matcher m = pt.matcher(text);
\t \t StringBuilder sb = new StringBuilder();
\t \t while (m.find()) {
\t \t \t sb.append(m.group()).append(",");
\t \t }
\t \t String[] phones = sb.toString().split(",");
\t \t Intent i = new Intent(this, Contacts.class);
\t \t i.putExtra("phones", phones);
\t \t startActivity(i);
\t \t /*------------------------------------------------email catcher-----------*/
\t \t String email = _field.getText().toString();
\t \t String EMAIL_PATTERN="^[email protected]+\\..+$";
\t \t Pattern pp = Pattern.compile(EMAIL_PATTERN);
\t \t Matcher e = pp.matcher(email);
\t \t StringBuilder sc = new StringBuilder();
\t \t while (e.find()) {
\t \t \t sc.append(e.group()).append(",");
\t \t }
\t \t String[] emails = sc.toString().split(",");
\t \t Intent j = new Intent(this, Contacts.class);
\t \t j.putExtra("emails", emails);
\t \t startActivity(j);
\t }
上述代碼是用於識別從下面的edittext.The碼電話號碼和電子郵件是其中的電話號碼和電子郵件的值應被傳遞到
的意圖 Intent phone=getIntent();
String [] phones = phone.getStringArrayExtra("phones");
edtTxtContactNumber.setText(phones[0]);
Intent email=getIntent();
String [] emails = email.getStringArrayExtra("emails");
edtTxtContactEmail.setText(emails[0]);
因此,它是possib當我點擊一個按鈕時,爲了傳遞多個值?爲什麼當我試圖在同一時間傳遞多個值時,我得到了nullpointerexception?我認爲我必須在startactivity()上做些什麼。
你從哪裏得到的空指針?在一個意圖中傳遞2個值時,代碼的外觀如何? – AlbAtNf
你開始兩次活動,你有兩個意圖。刪除第二個。 –
你應該把額外的值放在一個意圖。 – jomartigcal