您好,登錄后才能下訂單哦!
MyAdapter自定義適配器:
//具體方法如下:
-------------------------------------------------------------------------------------------
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 1,找到控件
lv = (ListView) findViewById(R.id.lv_list);
// 2,定義適配器
// >>>>>>>>>>>>>>>>>>>2.3自定義適配器
MyAdapter adapter = new MyAdapter();
// 3,加載適配器
lv.setAdapter(adapter);
}
private class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return objects.length;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// 加載布局 activity加載布局
/*
* LayoutInflater inflater=getLayoutInflater();
* inflater.inflate(resource, root);
*/
View contentView = View.inflate(getApplicationContext(),
R.layout.list_item, null);
// 找到布局里面的控件
ImageView iv = (ImageView) contentView.findViewById(R.id.iv_logo);
TextView tv = (TextView) contentView.findViewById(R.id.tv_name);
// 加載相應數據
iv.setImageResource(imgs[position]);
tv.setText(objects[position]);
return contentView;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------
撥號功能
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//添加意圖
Intent intent = new Intent();
//添加動作
intent.setAction(intent.ACTION_CALL);
//添加數據
intent.setData(Uri.parse("tel:"+phones[position]));
startActivity(intent);
}
});
-------------------------------------------------------------------------------------------
短信功能(頁面跳轉)
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i=new Intent(getApplicationContext(), SmsActivity.class);
i.putExtra("number", phones[position]);
startActivity(i);
return true;
}
});
-------------------------------------------------------------------------------------------
在用模擬器實現打電話發送短信等功能時需要在運行給它授予權限(授權方法:AndtoidManifest------>Permissions----->Add---->Uses Permission----->選擇要授予的權限---->Ctrl+s),若想實現發短信功能還需要先進行注冊(注冊方法:AndtoidManifest------>AndroidManifesf.xml------>建一個<activity (這里寫入android:name="com.eduask.dialing.類名")></activity>標簽)
在寫代碼時常范的錯誤:用LinearLayout時要記得給<LinearLayout設置寬度和高度></LinearLayout>不然將無法顯示寫在LinearLayout中的內容!切記-。-、、!!!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。