自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (2)
  • 收藏
  • 关注

空空如也

循环viewpager

android循环的播放viewpager

2013-11-25

package com.example.f1_telephone;

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.ListView; 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 List<TelephoneBean>list=new ArrayList<TelephoneBean>(); 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 List<TelephoneBean>list=new ArrayList<TelephoneBean>(); public TelephoneAdapter(Context context,List<TelephoneBean>list) { 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; } }

2013-09-11

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除