-1
これまでのところ、私はAndroid開発の初心者ですが、連絡先アプリケーションを作成しようとしていますが、AlertDialogがあるコードのこの部分に苦労しています。 (連絡先の情報、選択された情報)を表示し、自分のアクティビティ(ActivitySMS.class)に移動させますが、問題はないようですが、アプリケーションを実行して表示されるAlertDialogから番号を選択すると、終了する。ログには、どこに問題があるのかを理解し理解する価値のあるものはありません。AlertDialogとIntent
public class AgendaActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agenta);
ContentResolver resolver = getContentResolver();
Cursor mCursor = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
String[] contacts = {
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts._ID,
};
int[] views = new int[]{
android.R.id.text1
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,
mCursor,
contacts,
views,
0);
// Bind to our new adapter.
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
final Cursor phoneCursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?",
new String[]{"" + id},
null);
assert phoneCursor != null;
final int nTelephones = phoneCursor.getCount();
final String[] telephones = new String[nTelephones];
int x = 0;
while (phoneCursor.moveToNext()) {
int col = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
telephones[x++] = phoneCursor.getString(col);
}
//Cursor Close
phoneCursor.close();
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Telephone Selection");
builder.setItems(telephones, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int item) {
String currentNumber = "smsto: " + (telephones[item]);
Intent sentIntent = new Intent(AgendaActivity.this, ActivitySMS.class);
sentIntent.setData(Uri.parse(currentNumber));
startActivity(sentIntent);
}
});
AlertDialog alert = builder.create();
alert.show();
}
この障害を克服する方法はありますか?
のように、後であなたの活動にその値を読み取ることができ
によってライン
sendIntent.setData(Uri.parse(currentNumber));
を交換してください。 –