編輯:關於android開發
調用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(); } }); } }
基於 VLC 的 Android 多媒體解決方案,vlcandroid前段時間項目中需要在 Android 中播放視頻、流媒體、查看監控,就研究了一下 Android 多
安卓開源項目周報0208,安卓開源項目0208 由OpenDigg 出品的安卓開源項目周報第七期來啦。我們的安卓開源周報集合了OpenDigg一周來
Android開發學習之路-3DTouch效果模仿,android-3dtouch3D Touch是什麼效果的大家應該都知道了。什麼?不知道,那也沒辦法呀,我也沒有iPh
android學習——LinearLayout線性布局,linearlayout布局LinearLayout線性布局 LinearLayout是一種線型的