我想只在myast里面显示我的Toast里面的字符串编号,但是我无法找到那个东西。欢迎任何帮助!
if(cursor.moveToFirst())
{
do
{
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
{
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{ id }, null);
while (pCur.moveToNext())
{
String name = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
list.add(name + "\n" + number);
break;
}
pCur.close();
}
} while (cursor.moveToNext()) ;
}
适配器不重要的东西
spinnerClickListener();
}
用于图像按钮的onclick方法,以在吐司中显示所选的联系电话号码。
public void spinnerClickListener(){
//spinner item button onclick listener
callBTN = (ImageButton)findViewById(R.id.call);
mySpinner = (Spinner)findViewById(R.id.contacts);
callBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Selected number :" + "\n" + mySpinner.getSelectedItem(), Toast.LENGTH_LONG).show();
}
});
}
提前感谢!
答案 0 :(得分:0)
你应该使用这个
mySpinner.getSelectedItem().toString()
而不是
mySpinner.getSelectedItem()