MyAdapter自定义适配器:

//具体方法如下:

-------------------------------------------------------------------------------------------

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//1,找到控件

lv=(ListView)findViewById(R.id.lv_list);

//2,定义适配器

//>>>>>>>>>>>>>>>>>>>2.3自定义适配器

MyAdapteradapter=newMyAdapter();

//3,加载适配器

lv.setAdapter(adapter);

}

privateclassMyAdapterextendsBaseAdapter{

@Override

publicintgetCount(){

//TODOAuto-generatedmethodstub

returnobjects.length;

}

@Override

publicViewgetView(intposition,ViewconvertView,ViewGroupparent){

//加载布局activity加载布局

/*

*LayoutInflaterinflater=getLayoutInflater();

*inflater.inflate(resource,root);

*/

ViewcontentView=View.inflate(getApplicationContext(),

R.layout.list_item,null);

//找到布局里面的控件

ImageViewiv=(ImageView)contentView.findViewById(R.id.iv_logo);

TextViewtv=(TextView)contentView.findViewById(R.id.tv_name);

//加载相应数据

iv.setImageResource(imgs[position]);

tv.setText(objects[position]);

returncontentView;

}

@Override

publicObjectgetItem(intposition){

//TODOAuto-generatedmethodstub

returnnull;

}

@Override

publiclonggetItemId(intposition){

//TODOAuto-generatedmethodstub

return0;

}

}

--------------------------------------------------------------------------------------------------------------------------------------------------

拨号功能

lv.setOnItemClickListener(newOnItemClickListener(){

@Override

publicvoidonItemClick(AdapterView<?>parent,Viewview,

intposition,longid){

//添加意图

Intentintent=newIntent();

//添加动作

intent.setAction(intent.ACTION_CALL);

//添加数据

intent.setData(Uri.parse("tel:"+phones[position]));

startActivity(intent);

}

});

-------------------------------------------------------------------------------------------

短信功能(页面跳转)

lv.setOnItemLongClickListener(newOnItemLongClickListener(){

@Override

publicbooleanonItemLongClick(AdapterView<?>parent,Viewview,

intposition,longid){


Intenti=newIntent(getApplicationContext(),SmsActivity.class);

i.putExtra("number",phones[position]);

startActivity(i);


returntrue;

}

});


-------------------------------------------------------------------------------------------


在用模拟器实现打电话发送短信等功能时需要在运行给它授予权限(授权方法:AndtoidManifest------>Permissions----->Add---->Uses Permission----->选择要授予的权限---->Ctrl+s),若想实现发短信功能还需要先进行注册(注册方法:AndtoidManifest------>AndroidManifesf.xml------>建一个<activity (这里写入android:name="com.eduask.dialing.类名")></activity>标签)

在写代码时常范的错误:用LinearLayout时要记得给<LinearLayout设置宽度和高度></LinearLayout>不然将无法显示写在LinearLayout中的内容!切记-。-、、!!!