浅析Android手机卫士保存手机安全号码
程序员文章站
2024-02-27 23:21:21
推荐阅读:
浅析android手机卫士sim卡绑定
深入浅析android手机卫士保存密码时进行md5加密
详解android 手机卫士设置向导页面
浅析andro...
推荐阅读:
调用listview对象的setonitemclicklistener()方法,设置条目的点击事件,参数:onitemclicklistener对象
使用匿名内部类实现,重写onclick()方法,传递进来的参数:listview,当前view,position,id
根据索引位置把当前这条电话号码传回去
调用list对象的get()方法,得到map,调用get(key)方法,得到这条电话
调用setresult()方法,返回去数据,参数:响应码,intent对象
获取intent对象,new出来
调用intent对象的putextra(key,val),把电话放进去
调用finish()方法关闭当前页面
开启这个的activity使用的是startactivityforresult()
重写onactivityresult()方法,传递进来intent对象
判断intent对象是否为null
调用intent对象的getstringextra()方法,获取到电话号码
把电话放在edittext上,当点击下一步的时候保存到sp中
activity
package com.qingguow.mobilesafe; import android.content.intent; import android.content.sharedpreferences; import android.content.sharedpreferences.editor; import android.os.bundle; import android.text.textutils; import android.view.view; import android.widget.edittext; import android.widget.toast; public class secguide3activity extends basesecguideactivity { private edittext et_sec_phone; private sharedpreferences sp; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_lost_find3); et_sec_phone = (edittext) findviewbyid(r.id.et_sec_phone); sp = getsharedpreferences("config", mode_private); string phone = sp.getstring("secphone", ""); et_sec_phone.settext(phone); } public void nextstep(view v) { shownext(); } public void prestep(view v) { showpre(); } @override public void showpre() { intent intent = new intent(this, secguide2activity.class); startactivity(intent); finish(); } @override public void shownext() { string phone = et_sec_phone.gettext().tostring().trim(); if (textutils.isempty(phone)) { toast.maketext(this, "请填写安全号码", 1).show(); return; } editor editor = sp.edit(); editor.putstring("secphone", phone); editor.commit(); intent intent = new intent(this, secguide4activity.class); startactivity(intent); finish(); } /** * 选择联系人 */ public void selectcontacts(view v) { intent intent = new intent(this, selectcontactsactivity.class); startactivityforresult(intent, 0); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { // todo auto-generated method stub super.onactivityresult(requestcode, resultcode, data); if (data != null) { string phone = data.getstringextra("phone").replace("-", "") .replace(" ", ""); et_sec_phone.settext(phone); } } }
selectcontactsactivity
package com.qingguow.mobilesafe; import java.util.list; import java.util.map; import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.listview; import android.widget.simpleadapter; import com.qingguow.mobilesafe.utils.phonecontactsutil; /** * 选择联系人 * @author taoshihan * */ public class selectcontactsactivity extends activity { private listview lv_select_contacts; private list<map<string,string>> contacts; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_select_contacts); lv_select_contacts=(listview) findviewbyid(r.id.lv_select_contacts); contacts=phonecontactsutil.getcontacts(this); lv_select_contacts.setadapter(new simpleadapter(this, contacts, r.layout.select_contacts_item, new string[]{"name","phone"}, new int[]{r.id.tv_contact_name,r.id.tv_contact_phone})); lv_select_contacts.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int position, long arg3) { string phone=contacts.get(position).get("phone"); intent data=new intent(); data.putextra("phone", phone); setresult(0, data); finish(); } }); } }