編輯:關於android開發
參考代碼:
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.telephony.PhoneNumberUtils;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class App extends Activity {
private static final String TAG="App";
ListView listView;
ListAdapter adapter; //聲明一個適配器名稱
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
LinearLayout linearLayout=new LinearLayout(this);//實例化linearLayout,獲得其對象
linearLayout.setOrientation(LinearLayout.VERTICAL);//設置布局方式,這裡面是垂直分布
linearLayout.setBackgroundColor(Color.BLACK);//設置背景顏色
LinearLayout.LayoutParams param =
new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);//配置layout的長和寬 鏈接顯示LayoutParams的用法
listView=new ListView(this);
listView.setBackgroundColor(Color.BLACK);
linearLayout.addView(listView,param);//動態添加View
this.setContentView(linearLayout);
//從數據庫獲取聯系人姓名和電話號碼
Cursor cur=this.getContentResolver().query(People.CONTENT_URI,null, null,null,null);
adapter=new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cur,new String[]{People.NAME,People.NUMBER},new int[]{android.R.id.text1,android.R.id.text2});
//SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) 構造函數參數
this.startManagingCursor(cur);
listView.setAdapter(adapter);
//listView.setEmptyView(findViewById(R.id.empty));
listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
//openToast("滾動到:"+arg0.getSelectedItemId());
//短信發送
// PendingIntent pi = PendingIntent.getActivity(App.this,0,new Intent
(App.this,App.class),0);
// SmsManager sms = SmsManager.getDefault();
// sms.sendTextMessage("5554", null, "message", pi, null);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
// String[] names=((CursorWrapper)listView.getItemAtPosition(position)).getColumnNames
();
//從指針的封裝類中獲得選中項的電話號碼並撥號
CursorWrapper wrapper=(CursorWrapper)listView.getItemAtPosition(position);//返回值是Object類需要向下轉型成CursorWrapper類型
int columnIndex=wrapper.getColumnIndex(People.NUMBER);//返回從0開始的索引,如果列名不存在將返回-1
if(!wrapper.isNull(columnIndex)){
String number=wrapper.getString(columnIndex);
Log.d(TAG,"number="+number);
// //判斷電話號碼的有效性
if(PhoneNumberUtils.isGlobalPhoneNumber(number)){
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel://"+ number));
startActivity(intent);
}
}
}
});
}
private void openToast(String str){
Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
}
}
Volley,volley框架 一 網絡請求 1.get方式請求數據 // 1 創建一個請求隊列 RequestQueue requestQueue = Vo
Android逆向之旅---解析編譯之後的AndroidManifest文件格式 一、前言 今天又是周六了,閒來無事,只能寫文章了呀,今天我們繼續來看逆向的相關知識,我們
Android Scroll詳解(一):基礎知識 Android Scroll詳解(一):基礎知識 在前邊
ViewPager應用引導界面,viewpager引導界面如圖設置的一種引導頁的開啟這個引用時先將圖片進行一個動畫當動畫結束時進入到了引導頁面 &
Android開發3:Intent、Bundle的使用和ListView