-4

当用户输入联系人号码时,我需要显示联系人姓名。然后点击显示联系人姓名按钮。我的布局 Xml 文件内容 3 字段 1.编辑文本(用户输入联系人号码的位置) 2.文本视图(按下按钮时显示联系人姓名的位置) 3.按钮 这里我的活动类更好地理解

public class ContactNameActivity extends Activity
{

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Button buttonshow = (Button) findViewById(R.id.button_ShowName);
        final EditText textPhoneNo = (EditText) findViewById(R.id.Edittext_Number);
        final TextView tv=(TextView)findViewById(R.id.tv_ContactName);
        buttonshow.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    //here i need String ContactName

                    tv.setText(String.valueOf(ContactName));

                }

            });

    }
}
4

1 回答 1

-1
private String getContactNameFromNumber(String number) { 
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));


    Cursor cursor = context.getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},null,null,null);
    if (cursor.moveToFirst())
    {
        name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
    }   


    return name;

} 
于 2013-07-28T07:00:13.200 回答