设置安全号码
android:layout_toLeftOf="@id/safe_textview" 该组件的右边和指定组件的左边对齐,默认在Top位置 |
步骤: 1、点击选择联系人按钮,开启选择联系人的Activity WizardSetupActivity3.java /**
* 1、选择联系人
* @param view
*/
public void selectContact(View view) {
Intent intent = new Intent(this, ListContactsActivity.class);
startActivityForResult(intent, 0);
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// 接收传递过来的数据
if (data != null) {
Bundle extras = data.getExtras();
String phone = extras.getString("safenum");
et_setup3_phone.setText(phone);
}
} 2、然后将选择的联系人的号码,显示在安全号码的EditText上,当然也可以手动输入 a ) ListContactsActivity.java /**
* 10、列举系统联系人列表ListContactsActivity
*
* @author hacket
*
*/
public class ListContactsActivity extends Activity {
private ListView lv_activity_contacts;
private List<ContactInfo> allContacts;// 所有联系人信息
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_contacts);
lv_activity_contacts = (ListView) this.findViewById(R.id.lv_activity_contacts);
// 获取系统所有联系人的信息
allContacts = ContactInfoProvider.getAllContacts(ListContactsActivity.this);
lv_activity_contacts.setAdapter(new MyAdapter());
// 为ListView中每一个item注册点击事件
lv_activity_contacts.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ContactInfo contactInfo = allContacts.get(position);// 点击哪一个item
String safenum = contactInfo.getPhone();// 获取该位置的电话号码
// 将电话号码传递过去
Intent data = new Intent();
Bundle extras = new Bundle();
extras.putString("safenum", safenum);
data.putExtras(extras);
setResult(0, data);// 设置数据给开启它的Activity
ListContactsActivity.this.finish();// 销毁当前Activity
}
});
}
/**
* 1、联系人ListView的Adapter
* @author hacket
*/
private class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
if (allContacts != null && allContacts.size() > 0) {
return allContacts.size();
}
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(ListContactsActivity.this, R.layout.activity_list_contacts, null);
TextView tv_name = (TextView) view.findViewById(R.id.tv_contacts_name);
TextView tv_phone = (TextView) view.findViewById(R.id.tv_contacts_phone);
TextView tv_email = (TextView) view.findViewById(R.id.tv_contacts_email);
ContactInfo contactInfo = allContacts.get(position);
tv_name.setText(contactInfo.getName());
tv_phone.setText(contactInfo.getPhone());
tv_email.setText(contactInfo.getEmail());
return view;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
} b) ContactInfoProvider.java
@Override
public void next(View view) {
Editor edit = spf.edit();// 将返回的phone存入
edit.putString("safenum", et_setup3_phone.getText().toString());
edit.commit();
Intent intent = new Intent(this, WizardSetupActivity4.class);
startActivity(intent);
this.finish();
overridePendingTransition(R.anim.tran_next_in, R.anim.tran_next_out);
}
|
结果: |