如何将数字值设置为字符串settext到textview

时间:2018-09-10 12:56:23

标签: android string contacts settext

在同一个项目中工作,我下载了多联系人库,它只给我提供我的联系人姓名,就是联系电话,我将字符串更改为int,但现在却行不通

这可能是代码

public class MainActivity extends AppCompatActivity {

private static final int CONTACT_PICKER_REQUEST = 91;
public TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btnOpenPicker = (Button) findViewById(R.id.btnOpenPicker);
    textView = (TextView)findViewById(R.id.textView);
    btnOpenPicker.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
                new MultiContactPicker.Builder(MainActivity.this) //Activity/fragment context
                        .theme(R.style.MyCustomPickerTheme) //Optional - default: MultiContactPicker.Azure
                        .hideScrollbar(false) //Optional - default: false
                        .showTrack(true) //Optional - default: true
                        .searchIconColor(Color.WHITE) //Optional - default: White
                        .setChoiceMode(MultiContactPicker.CHOICE_MODE_MULTIPLE) //Optional - default: CHOICE_MODE_MULTIPLE
                        .handleColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary)) //Optional - default: Azure Blue
                        .bubbleColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary)) //Optional - default: Azure Blue
                        .bubbleTextColor(Color.WHITE) //Optional - default: White
                        .showPickerForResult(CONTACT_PICKER_REQUEST);
            }else{
                Toast.makeText(MainActivity.this, "Remember to go into settings and enable the contacts permission.", Toast.LENGTH_LONG).show();
            }
        }



    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    String phoneNo = null ;
    if(requestCode == CONTACT_PICKER_REQUEST){
        if(resultCode == RESULT_OK) {
            List<ContactResult> results = MultiContactPicker.obtainResult(data);
          //  Log.d("MyTag", results.get(0).getPhoneNumbers());
           phoneNo =results.get(0).getPhoneNumbers();
            textView.setText(phoneNo);
                    Toast.makeText(MainActivity.this, ("bbbbbbbbbbbbbbbb" + phoneNo ),Toast.LENGTH_LONG).show();
        } else if(resultCode == RESULT_CANCELED){
            System.out.println("User closed the picker without selecting items.");
        }
    }
}

} 请您修复它

2 个答案:

答案 0 :(得分:1)

getPhoneNumbers()返回字符串类型的列表。尝试

List<String> phoneNumbers = results.get(0).getPhoneNumbers()
for(int i=0;i<phoneNumbers.length.size();i++)
   phoneNumbers.get(i);//This gives you the phone numbers

答案 1 :(得分:0)

您可以尝试以下方法:

String str = results.get(0).getContactID(); //this also return String 
int i = Integer.parseInt(str); //convert it to int