文件名称:
package com.example.f1_telephone;
开发工具:
文件大小: 469byte
下载次数: 0
上传时间: 2013-09-11
详细说明: package com.example.f1_telephone; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.PhoneLookup; import android.database.Cursor; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Lis tView; import android.content.ContentResolver; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; public class MainActivity extends Activity implements OnItemClickListener{ private ListView listView; private TelephoneAdapter adapter; private Listlist=new ArrayList(); private TelephoneBean bean; Intent phoneIntent; String str; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView=(ListView) findViewById(R.id.listView); //得到ContentResolver对象 ContentResolver cr = getContentResolver(); //取得电话本中开始一项的光标 Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); //向下移动光标 while(cursor.moveToNext()) { //取得联系人名字 int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); String contact = cursor.getString(nameFieldColumnIndex); //取得电话号码 String ContactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + ContactId, null, null); while(phone.moveToNext()) { String PhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); bean=new TelephoneBean(contact, PhoneNumber); list.add(bean); } } adapter=new TelephoneAdapter(this, list); listView.setAdapter(adapter); cursor.close(); listView.setOnItemClickListener(this); } private void send1(String number){ Uri uri = Uri.parse("smsto:" + number); Intent sendIntent = new Intent(Intent.ACTION_VIEW, uri); startActivity(sendIntent); } @Override public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) { str=list.get(arg2).getNumber(); phoneIntent = new Intent("android.intent.action.CALL",Uri.parse("tel:" + str)); AlertDialog dialog=new AlertDialog.Builder(this).setTitle("请选择服务项目").setItems(new String[]{"拨打电话","发送短信"}, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(which==0){ startActivity(phoneIntent); } if(which==1){ send1(str); } } }).setNegativeButton("取消", null).show(); } } package com.example.f1_telephone; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class TelephoneAdapter extends BaseAdapter{ private Context context; private Listlist=new ArrayList(); public TelephoneAdapter(Context context,Listlist) { this.context=context; this.list=list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int arg0) { return list.get(arg0); } @Override public long getItemId(int arg0) { return arg0; } @Override public View getView(int arg0, View arg1, ViewGroup arg2) { Holde holde=new Holde(); if(arg1==null){ arg1=LayoutInflater.from(context).inflate(R.layout.list_telephone, null); holde.tvname=(TextView) arg1.findViewById(R.id.tv_name); holde.tvnumber=(TextView) arg1.findViewById(R.id.tv_number); arg1.setTag(holde); } else{ holde=(Holde) arg1.getTag(); } TelephoneBean telephoneBean=list.get(arg0); holde.tvname.setText(telephoneBean.getName()); holde.tvnumber.setText(telephoneBean.getNumber()); return arg1; } private class Holde{ public TextView tvname; public TextView tvnumber; } } package com.example.f1_telephone; public class TelephoneBean { public String name; public String number; public TelephoneBean(String name,String number) { this.name=name; this.number=number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.