QQ界面學(xué)習(xí)總結(jié).doc_第1頁
QQ界面學(xué)習(xí)總結(jié).doc_第2頁
QQ界面學(xué)習(xí)總結(jié).doc_第3頁
QQ界面學(xué)習(xí)總結(jié).doc_第4頁
QQ界面學(xué)習(xí)總結(jié).doc_第5頁
已閱讀5頁,還剩15頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

個(gè)人學(xué)習(xí)總結(jié)1.TextView的使用其使用步驟具體如下:在Layout/XXX.xml中定義一個(gè)TextView, 然后設(shè)置一些屬性 其具體知識(shí)可以參考:/reference/android/widget/TextView.html 在src/xxx.java中聲明一個(gè) TextViewprivate TextView mTextView01;利用findViewById()方法獲取xxx.xml中的TextViewmTextView01 = (TextView) findViewById(R.id.TextView01);2.EditView的使用和TextView類似3.Button的使用與TextView、EditView的區(qū)別主要是:一般為Button綁定一個(gè)監(jiān)聽器,操作如下在Layout/XXX.xml中定義一個(gè)Button在src/xxx.java中聲明一個(gè) Button利用findViewById()方法獲取xxx.xml中的Button寫監(jiān)聽器代碼button_exit.setOnClickListener(new OnClickListener()public void onClick(View v)/根據(jù)實(shí)際需要寫代碼,注意這里采用的是匿名內(nèi)部類的方式);4. AlertDialog對(duì)話框的使用new AlertDialog.Builder(XXX.this).setTitle(Android提示).setMessage(您確定靜音登錄嗎?).setPositiveButton(確定,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog, int whichButton) / TODO Auto-generated method stub根據(jù)實(shí)際需要填寫代碼 ).setNegativeButton(取消, new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog, int whichButton) / TODO Auto-generated method stub 根據(jù)實(shí)際需要填寫代碼 ) .show();5.checkBox的使用這里省略定義、聲明、獲取都已經(jīng)省略了,關(guān)鍵是寫checkBox的監(jiān)聽器:setOnCheckedChangeListener(new OnCheckedChangeListener() public void onCheckedChanged(CompoundButton arg0, boolean arg1) / TODO Auto-generated method stub/ 根據(jù)實(shí)際情況書寫相關(guān)代碼/這里采用的也是匿名內(nèi)部類的方式 );6.子菜單(options menu)的使用options menu在屏幕底部最多只能顯示6個(gè)菜單項(xiàng)/* * 創(chuàng)建子菜單,在點(diǎn)擊Mune時(shí)會(huì)彈出子菜單 */Overridepublic boolean onCreateOptionsMenu(Menu menu) / TODO Auto-generated method stubsuper.onCreateOptionsMenu(menu);menu.add(0,MENU_SETTINGS, 0, 系統(tǒng)設(shè)置);menu.add(0, MENU_CHANGPWD, 0,修改密碼);return true;/* * 為子菜單寫監(jiān)聽器事件 */Overridepublic boolean onOptionsItemSelected(MenuItem item) / TODO Auto-generated method stubswitch(item.getItemId()case MENU_SETTINGS: /根據(jù)需要設(shè)置代碼case MENU_CHANGPWD:/ /根據(jù)需要設(shè)置代碼return super.onOptionsItemSelected(item);7.兩個(gè)Activity之間的跳轉(zhuǎn) /生成一個(gè)Intent對(duì)象Intent intent = new Intent();/設(shè)置Intent對(duì)象要啟動(dòng)的Activityintent.setClass(xxx.this, xxx1.class);/通過Intent對(duì)象啟動(dòng)另外一個(gè)Activityxxx.this.startActivity(intent);8.使用XML來創(chuàng)建配置文件其具體操作如下:生成一個(gè)Preference資源文件,命名為xxx.xml,具體內(nèi)容如下 在xxx.java中獲取這個(gè)xxx.xml文件代碼如下:addPreferencesFromResource(R.xml.preferences);根據(jù)key找到控件XXXCheckBox整個(gè)java代碼可以參考:/franksunny/archive/2011/10/21/2219890.html有參考價(jià)值的代碼:SharedPreferences settings = getSharedPreferences(settings, 0);/自動(dòng)填充密碼 String strPswInputLable= settings.getString(getString(R.string.strPswInputLabel), null);/記住密碼checkbox設(shè)置final CheckBox mlogin_cb_savepwd = (CheckBox) findViewById(R.id.login_cb_savepwd);/記住密碼checkbox 對(duì)象 String ck1 = settings.getString(getString(R.string.saveaccount),null);/checkbox記錄的值if (ck1 != null & ck1.equals(true) mlogin_cb_savepwd.setChecked(true);mlogin_cb_savepwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() /Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean arge) / TODO Auto-generated method stubSharedPreferences settings = getSharedPreferences(settings, 0);String ck1 = settings.getString(getString(R.string.saveaccount), null);if (ck1 != null & ck1.equals(true) settings.edit()putString(getString(R.string.saveaccount),false).commit();settings.edit().remove(getString(R.string.saveaccount).commit();mlogin_cb_savepwd.setChecked(false););9.Sqlite數(shù)據(jù)庫的使用在Android應(yīng)用中創(chuàng)建數(shù)據(jù)庫后數(shù)據(jù)庫文件是存儲(chǔ)在/data/ data/應(yīng)用包名/databases/下。在Android中使用到SQLite會(huì)涉及到以下三個(gè)類或接口:SQLiteOpenHelperSQLiteOpenHelper 構(gòu)造方法,一般傳遞一個(gè)要?jiǎng)?chuàng)建的數(shù)據(jù)庫名稱name參數(shù)onCreate 創(chuàng)建數(shù)據(jù)庫時(shí)調(diào)用onUpgrade 版本更新時(shí)調(diào)用getReadableDatabase 創(chuàng)建或打開一個(gè)只讀數(shù)據(jù)庫getWritableDatabase 創(chuàng)建或打開一個(gè)讀寫數(shù)據(jù)庫SQLiteDatabaseopenOrCreateDatabase 打開或者創(chuàng)建數(shù)據(jù)庫insert 添加一條記錄delete 刪除一條記錄query 查詢記錄update 更新記錄execSQL 執(zhí)行一條SQL語句close 關(guān)閉數(shù)據(jù)庫CursorgetCount 總記錄條數(shù)isFirst 判斷是否第一條記錄isLast 判斷是否最后一條記錄moveToFirst 移動(dòng)到第一條記錄moveToLast 移動(dòng)到最后一條記錄move 移動(dòng)到指定記錄moveToNext 移動(dòng)到下一條記錄moveToPrevious 移動(dòng)到上一條記錄getColumnIndexOrThrow根據(jù)列名稱獲得列索引getInt 獲得指定列索引的int類型值getString 獲得指定列索引的String類型值具體操作如下:創(chuàng)建一個(gè)類Class繼承SQLiteOpenHelper,具體可以參考下面一段代碼public class DB public static final String KEY_ACCOUNTS=accounts;public static final String KEY_SAVEACCOUNT=saveaccount;public static final String KEY_PWD=pwd;public static final String KEY_NAME=name;public static final String KEY_IMAGE=image;public static final String KEY_AGE=age;public static final String KEY_ADDRESS=address;public static final String KEY_GENDER=gender;public static final String KEY_VISIBLE=visible;public static final String KEY_SAVEPWD=savepwd;public static final String KEY_OPENVIBRA=openvibra;public static final String KEY_RECEIVEGROUPMSG=receivegroupmsg;public static final String KEY_QUITE=quite;private Context mctx;private DatabaseHelper dbHelper;private String accounts;private static SQLiteDatabase db;/定義一個(gè)SQLiteDatabase的變量/Constructor 構(gòu)造函數(shù)public DB(Context mctx)this.mctx=mctx;public void open() dbHelper=new DatabaseHelper(mctx);trydb=dbHelper.getWritableDatabase();catch(SQLiteException e)db=dbHelper.getReadableDatabase();public static class DatabaseHelper extends SQLiteOpenHelperprivate static final String DATABASE_NAME=load.db;private static final int DATABASE_VERSION=2;/版本號(hào)/* * 創(chuàng)建表名 */ static final String DATABASE_TABLE=user;/* * 創(chuàng)建一個(gè)字符常量 */private static final String DATABASE_CREATE =CREATE TABLE user (+accounts int(10)PRIMARY KEY ,+saveaccount int(10),+pwd int(20), + name char(20),+image varchar(20),+age int(10),+address varchar(20),+gender char(20),+visible int(3),+savepwd int(3),+openvibra int(3),+receivegroupmsg int(3),+quite int(3)+); ;/*由于simpleCursorAdapter的方法只識(shí)別_id,所以, * 用到sqlite的simpleCursorAdapter時(shí),必須把數(shù)據(jù)表的主鍵命名為_id。*/public DatabaseHelper(Context context) super(context, DATABASE_NAME, null, DATABASE_VERSION);/ TODO Auto-generated constructor stub/創(chuàng)建數(shù)據(jù)庫Overridepublic void onCreate(SQLiteDatabase db) / TODO Auto-generated method stubdb.execSQL(DATABASE_CREATE);/更新數(shù)據(jù)庫Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) / TODO Auto-generated method stubdb.execSQL(DROP TABLE IF EXISTS +DATABASE_TABLE);onCreate(db);根據(jù)自己的實(shí)際需要數(shù)據(jù)庫管理類下面給出幾個(gè)參考代碼:/添加用戶,插入數(shù)據(jù):public long adduser(String accounts,String pwd,String saveaccount)/insert方法插入的一行記錄使用contentValues存放 ContentValues args=new ContentValues(); args.put(KEY_ACCOUNTS,accounts); args.put(KEY_PWD,pwd); args.put(KEY_SAVEACCOUNT,saveaccount); /返回新添記錄的行號(hào),該行號(hào)是一個(gè)內(nèi)部值,與主鍵id無關(guān),發(fā)生錯(cuò)誤返回-1 return db.insert(DatabaseHelper.DATABASE_TABLE, null, args); /添加更新,修改數(shù)據(jù):public boolean update(String accounts, String pwd) ContentValues args = new ContentValues(); args.put(KEY_PWD, pwd); return db.update(DatabaseHelper.DATABASE_TABLE, args, accounts=?, new Stringaccounts) 0; /作者定義的新類public Cursor checkUser(String accounts,String pwd)Cursor mCursor=(SQLiteCursor) db.query(true, DatabaseHelper.DATABASE_TABLE,new StringKEY_ACCOUNTS, accounts=? and pwd=?,new Stringaccounts,pwd, null, null, null, null);System.out.println(mCursor);return mCursor;/* * 我自己添加的用來保存用戶個(gè)人信息:account、name、gender、age、image、address * */public long update(String accounts,String name,String sex,String age,int image,String address)/insert方法插入的一行記錄使用contentValues存放 ContentValues args=new ContentValues(); args.put(KEY_ACCOUNTS,accounts); args.put(KEY_NAME,name); args.put(KEY_GENDER,sex); args.put(KEY_AGE, age); args.put(KEY_IMAGE, image); args.put(KEY_ADDRESS, address); /返回新添記錄的行號(hào),該行號(hào)是一個(gè)內(nèi)部值,與主鍵id無關(guān),發(fā)生錯(cuò)誤返回-1 /* * 關(guān)鍵問題是如何把第四個(gè)參數(shù)設(shè)置我要輸入的用戶名 */ return db. update(DatabaseHelper.DATABASE_TABLE, args, accounts=?,new Stringaccounts); 需要用到數(shù)據(jù)庫的地方進(jìn)行初始化數(shù)據(jù)庫、調(diào)用即可。數(shù)據(jù)庫中還經(jīng)常使用到Cursor Cursor 是每行的集合。使用 moveToFirst() 定位第一行。必須知道每一列的名稱,必須知道每一列的數(shù)據(jù)類型。Cursor 是一個(gè)隨機(jī)的數(shù)據(jù)源。關(guān)于 Cursor 的重要方法:close() 關(guān)閉游標(biāo),釋放資源。copyStringToBuffer(int columnIndex, CharArrayBuffer buffer) 在緩沖區(qū)中檢索請(qǐng)求的列的文本,將將其存儲(chǔ)。getColumnCount() 返回所有列的總數(shù)。getColumnIndex(String columnName) 返回指定列的名稱,如果不存在返回-1。getColumnIndexOrThrow(String columnName) 從零開始返回指定列名稱,如果不存在將拋出IllegalArgumentException 異常。getColumnName(int columnIndex) 從給定的索引返回列名。getColumnNames() 返回一個(gè)字符串?dāng)?shù)組的列名。getCount() 返回Cursor 中的行數(shù)。moveToFirst() 移動(dòng)光標(biāo)到第一行。moveToLast() 移動(dòng)光標(biāo)到最后一行。moveToNext() 移動(dòng)光標(biāo)到下一行。moveToPosition(int position) 移動(dòng)光標(biāo)到一個(gè)絕對(duì)的位置。moveToPrevious() 移動(dòng)光標(biāo)到上一行如何在利用圖片的路徑打開圖片:希望直接使用res/drawable中的圖片,就需要通過下面的方法了:獲取圖片的ID int resID = getResources().getIdentifier(imagename, drawable, org.crayzit.Test);/第一個(gè)參數(shù):圖片的名稱/第二個(gè)參數(shù):表示drawable目錄下的圖片/第三個(gè)參數(shù):應(yīng)用程序的包名,記得一定要加雙引號(hào)”pshowimage.setImageBitmap(BitmapFactory.decodeResource(getResources() , resID );或者是:Drawable image = getResources().getDrawable(resID);10.如何創(chuàng)建一個(gè)引導(dǎo)界面: Handler對(duì)象用法設(shè)計(jì)思路:創(chuàng)建一個(gè)handler的對(duì)象,然后調(diào)用里面postDelayed(Runnable r,long delaymillis)的方法Handler主要用于發(fā)送和處理和一個(gè)線程有關(guān)聯(lián)的消息隊(duì)列(MessageQueue)的消息和可運(yùn)行對(duì)象參考代碼:private final int SPLASH_DISPLAY_LENGHT = 5000; /延遲15秒 Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.splash); main_imageview=(LoadingView)findViewById(R.id.main_imageview); initLoadingImages();new Handler().postDelayed(new Runnable() / Override public void run() Intent mainIntent = new Intent(Splash.this,Load.class); Splash.this.startActivity(mainIntent); Splash.this.finish(); , SPLASH_DISPLAY_LENGHT); 補(bǔ)充:Handler基本概念: Handler主要用于異步消息的處理:當(dāng)發(fā)出一個(gè)消息之后,首先進(jìn)入一個(gè)消息隊(duì)列,發(fā)送消息的函數(shù)即刻返回,而另外一個(gè)部分逐個(gè)的在消息隊(duì)列中將消息取出,然后對(duì)消息進(jìn)行出來,就是發(fā)送消息和接收消息不是同步的處理。 這種機(jī)制通常用來處理相對(duì)耗時(shí)比較長(zhǎng)的操作。Handler 常用方法:post(Runnable) postAtTime(Runnable,long) postDelayed(Runnable long) sendEmptyMessage(int) sendMessage(Message) sendMessageAtTime(Message,long) sendMessageDelayed(Message,long) 以上post類方法允許你排列一個(gè)Runnable對(duì)象到主線程隊(duì)列中, sendMessage類方法, 允許你安排一個(gè)帶數(shù)據(jù)的Message對(duì)象到隊(duì)列中,等待更新.11.如何創(chuàng)建一個(gè)開機(jī)動(dòng)畫設(shè)計(jì)思想:創(chuàng)建一個(gè)類來繼承ImageView實(shí)現(xiàn)接口Runnable/使用postInvalidate();刷新12. RadioButton的使用這里也是主要介紹RadioButton監(jiān)聽器的有關(guān)代碼:setOnCheckedChangeListener(new OnCheckedChangeListener() public void onCheckedChanged(RadioGroup group, int checkedId) RadioButton sexRadio = (RadioButton)findViewById(checkedId);sexString = sexRadio.getText().toString(););13.Intent與Bundle的使用總結(jié)14.自定義listView的使用實(shí)現(xiàn)原理:自定義列表的Android程序,程序?qū)?shí)現(xiàn)一個(gè)使用自定義的適配器(Adapter)綁定數(shù)據(jù),通過contextView.setTag綁定數(shù)據(jù)有按鈕的ListView。系統(tǒng)顯示列表(ListView)時(shí),首先會(huì)實(shí)例化一個(gè)適配器,本文將實(shí)例化一個(gè)自定義的適配器。實(shí)現(xiàn)自定義適配器,必須手動(dòng)映射數(shù)據(jù),這時(shí)就需要重寫getView()方法,系統(tǒng)在繪制列表的每一行的時(shí)候?qū)⒄{(diào)用此方法。ListView在開始繪制的時(shí)候,系統(tǒng)自動(dòng)調(diào)用getCount()函數(shù),根據(jù)函數(shù)返回值得到ListView的長(zhǎng)度,然后根據(jù)這個(gè)長(zhǎng)度,調(diào)用getView()逐一畫出每一行。大致步驟如下:第一步:準(zhǔn)備主布局文件、組件布局文件等第二步:獲取并整理數(shù)據(jù)第三部:綁定數(shù)據(jù),這里我們是通過自己編寫Adapter類來完成的例子:注意的是我們?cè)O(shè)置 ListView 的 id 為 ”android:id/list”, 意思是我們引用 Android 已經(jīng)為我們定義好的一個(gè) id ,名字是 list ,如果你不定義成這樣,這個(gè) ListView 是不能被 ListActivity 識(shí)別的15. 可展開的列表組件(ExpandableListView)的使用方法總結(jié)ExpandableListView是一個(gè)垂直滾動(dòng)的顯示兩個(gè)級(jí)別(group,child)列表項(xiàng)的視圖。列表項(xiàng)來自ExpandableListAdapter,gourp可以單獨(dú)展開。步驟具體如下:1 在layout的xml文件中定義一個(gè)ExpandableListView參考代碼: 2 定義兩個(gè)List,用來存放控件中Group/Child中的String參考代碼:private List groupArray;private ListList childArray;對(duì)這兩個(gè)List進(jìn)行初始化,并插入一些數(shù)據(jù)groupArray = new ArrayList();childArray = new ArrayListList();groupArray.add(第一行);groupArray.add(第二行);List tempArray = new ArrayList();tempArray.add(第一條);tempArray.add(第二條);tempArray.add(第三條);for(int index = 0; index groupArray.size(); +index) childArray.add(tempArray);3 定義ExpandableListView的Adapter/ExpandableListView的Adapterpublic class ExpandableAdapter extends BaseExpandableListAdapterActivity activity;public ExpandableAdapter(Activity a)activity = a;public Object getChild(int groupPosition, int childPosition)return childArray.get(groupPosition).get(childPosition);public long getChildId(int groupPosition, int childPosition)return childPosition;public int getChildrenCount(int groupPosition)return childArray.get(groupPosition).size();public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent)String string = childArray.get(groupPosition).get(childPosition);return getGenericView(string);/ group method stubpublic Object getGroup(int groupPosition)return groupArray.get(groupPosition);public int getGroupCount()return groupArray.size();public long getGroupId(int groupPosition)return groupPosition;public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent)String string = groupArray.get(groupPosition);return getGenericView(string);/ View stub to create Group/Children s Viewpublic TextView getGenericView(String string)/ Layout parameters for the ExpandableListViewAbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 64);TextView text = new TextView(activity);text.setLayoutParams(layoutParams);/ Center the text verticallytext.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);/ Set the text starting positiontext.setPadding(36, 0, 0, 0);text.setText(string);return text;public boolean hasStableIds()return false;public boolean isChildSelectable(int groupPosition, int childPosition)return true;4 最后個(gè)定義好的ExpandableListView添加AdapterExpandableListView expandableListView =(ExpandableListView)findViewById(R.id.expandableListView);expandableListView.setAdapter(new ExpandableAdapter(Main.this)5 常用方法 expandGroup(int groupPos):在分組列表視圖中展開一組 setSelectedGroup(int groupPosition):設(shè)置選擇指定的組 setSelectedChild(ing groupPosition,int childPosition,boolean shouldExpandGroup):設(shè)置選擇指定的子項(xiàng) getPackedPositionGroup(long packedPosition):返回所選擇的組 getPackedPositionForChild(ing groupPosition,int childPosition):返回所選擇的子項(xiàng) getPackedPositionType(long packedPosition):返回所選擇的類型(group.child) isGroupExpanded(int groupPosition):判斷此組是否展開 ExpandableListContextMenuInfo info = (ExpandableListMenuInfo)item.getMenuInfo(); String title = (TextView)info.targetView).getText().toString(); int type = ExpandableListView.getPackedPositionType(info.packedPosition); if(type = ExpandableListView.PACKED_POSITION_TYPE_CHILD) int gourpPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); int childPos = ExpandableListView.getPackedPositiionChild(info.packedPosition); 16.android SD卡文件的讀取SD卡使用的是FAT(File Allocation Table)的文件系統(tǒng),不支持訪問模式和權(quán)限控制,SD卡適用于保存大尺寸的文件或者是一些無需設(shè)置訪問權(quán)限的文件Android模擬器支持SD卡,但模擬器中沒有缺省的SD卡,開發(fā)人員須在模擬器中手工添加SD卡的映像文件為了讀寫SD卡上的文件,必須在AndroidManifest.xml中添加讀寫SD卡的權(quán)限在SD卡上創(chuàng)建與刪除文件的權(quán)限 Android.permission.MOUNT_UNMOUNT_FIFESYSTEMS向SD卡寫入數(shù)據(jù)的權(quán)限 Android.permission.WRITE_EXTERNAL_STORAGE編程訪問SD卡方法一首先需要檢測(cè)系統(tǒng)的/mnt/sdcard目錄是否可用使用文件的輸入輸出流對(duì)SD卡里的文件進(jìn)行讀寫編程訪問SD卡方法二調(diào)用E

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論