android学习笔记

来源:互联网 发布:在淘宝上开店要钱吗 编辑:程序博客网 时间:2024/05/22 15:19

系统提供的对话框

警告AlertDialog,进度对话框ProgressDialog,日期选择对话框DatePickerDialog 时间选择对话框TimePickerDialog

常见事件监听器

OnClickListener,OnFocusChangeListener,OnKeyListener,OnTouchListener,OnCreateContextMenuListener

Bundle

//实例化Bundle对象,保存属性Bundle b=new Bundle();b.putString("name",name);b.putString("age",2);intent.putExtra("data",b);Intent intent=getIntent();Bundle b=intent.getBundleExtra("data");

自动完成文本框AutoCompleteTextView

private AutoCompleteTextView atv;atv=findViewById...String[] strs={"ab","ccc","dd"};ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_dropdown_item_lline,strs);atv.setAdapter(adapter);

选项卡Tab

public MainActivity extends TabActivity{public void onCreate(){TabHost th=getTabHost();LayoutInflater.from(this).inflate(R.layout.main,th.getTabContentView(),true);th.addTab(th.newTabSpec("all").setIndicator("all record").setContent(R.id.TextView01));th.addTab...th.addTab...}}

xml:<FrameLayout><TabHost><TextView text="all record"/><TextView text="all record"/><TextView text="all record"/></TabHost></FrameLayout>

进度条

对话框进度条,标题栏进度条,水平进度条

对话框进度条

public MainActivity{public void onCreate(){onClick(){showDialog(0);}}protected Dialog onCreateDialog(int id){ProgressDialog dialog=new ProgressDialog(this);dialog.setTitle("test");dialog.setIndeterminate(true);dialog.setMessage("loading");dialog.setCancelable(true);return dialog;}}

标题栏进度条

public class MainActivity{public void onCreate(){//设置窗口特征requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);setProgressBarIndeterminateVisibility(true);//showsetProgressBarIndeterminateVisibility(false);//hide}}

水平进度条

ProgressBar bar=findViewById...bar.incrementProgressBy(1);//增加进度bar.incrementProgressBy(-1);//减少

时间日期选择器

Calendar c=Calendar.getInstance();year=c.get(Calendar.YEAR);month=c.get(Calendar.MONTH);day=c.get(Calendar.DAY_OF_MONTH);protected Dialog onCreateDialog(int id){if(id==0){return new DatePickerDialog(this,l1,year,month,day);}else{return new TimePickerDialog(this,l2,hour,minute,false);}private OnDateSetListener l1=new OnDateSetListener(){public void onDateSet(){}};private OnTimeSetListener l2=new OnTimeSetListener(){public void onTimeSet(){}};}

ListView

public class Main extends ListActivity{onCreate(){String str={"a","b","c"};ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.simple_list_item,strs);setListAdapter(adapter);}}

SQLite

SQLite是嵌入式数据库引擎,针对内存等 资源有限制的设备提供一种高效的数据库引擎它没有服务器进程,所有的内容包含在同一个单文件 中。文件是跨平台的,可以自由复制

openOrCreateDatabase,private void createTable(SQLiteDatabase db){String sql="create table User(_id integer primary key autoincrement,name text,paswd text)";db.execSQL(sql);}db.deletedb.insert查询数据public Cursor query(String table,String[] columns,String selection,String[] selectionArgs,String groupBy,String having,String orderBy,String limit)Cursor是一个游标接口,提供遍历查询结果的方法常用方法:getCount,isFirst,isLast,moveToFirst,moveToLast,move(int offset),moveToNext,moveToPrevious,getInt,getString

ContentProvider

应用 程序之间的相互访问的统一接口,被定义在Content Provider中,包括增删改查Content Provider 用来保存和检索数据,使应用 程序间的相互访问数据成为可能,是跨应用程序共享数据的唯一方法ContentResolver中提供了和ContentProvider对应的方法,间接地通过操作ContentResolver来操作ContentProviderContentResolver通过应用程序的getContentResolver()获得。一般下,ContentProvider是单实例,但可有多个ContentResolver在不同的应用 程序和不同的进程之间和ContentProvider交互ContentProvider是通过URI对象来共享其数据。URI对象必须以"content://"开头private void query(){ContentResolver cr=getContentResolver();Uri uri=Contacts.People.CONTENT_URI;String[] projection={Contacts.PeopleColumns.NAME,Contacts.PeopleColumns.NOTES};String selection=Contacts.PeopleColumns.NAME+"=?";String[] selectionArgs={"yaohuiye"};String sortOrder=Contacts.PeopleColumns.NAME;Cursor c=cr.query(uri,projection,selection,selectionArgs,sortOrder);if(c.moveToFirst()){for(int i=0;i<c.getCount();i++){c.moveToPosition(i);int idx=c.getColumnIndexOrThrow(PeopleColumns.NAME);Log.i("test",c.getString(idx));}}}private void insert(){ContentResolver cr=getContentResolver();ContentValues values=new ContentValues();Uri url=Contacts.People.CONTENT_URI;values.put(People.NAME,"tom");values.put(People.NOTES,"i am tom");cr.insert(url,values);}

多媒体

播放音频和视频 用到MediaPlayer,JetPlayer类,录制音频及视频用到MediaRecorder类MediaPlayer p=MediaPlayer.create(this,R.raw.test);p.start();MediaPlayer m=new MediaPlayer();String path="/sdcard/test.mp3";m.setDataSource(path);m.prepare();m.start();String path="http://....mp3";Uri uri=Uri.parse(path);MediaPlayer p=MediaPlayer.create(this,uri);p.start();

操作图片

在android中操作图片是通过使用Drawable类来完成通过Bitmap和BitmapFactory类来读取文件 String path="/sdcard/beauty.jpg";Bitmap bm=BitmapFactory.decodeFile(path);setWallpaper(bm);//设置桌面

android中的动画

android中的动画 一种是Tween动画,可以使视图组件移动,放大,缩小及产生透明度的变化,另外是Frame动画,通过顺序播放排列好的图片实现

动态图形绘制的基本思路,创建一个类继承View类或继承SurfaceView类,覆盖onDraw方法,使用Canvas对象在界面上绘制不同的图形,使用invalidate方法刷新界面

android中的具体 的网络编程方式

针对TCP/IP的Socket,ServerSocket针对UDP的DatagramSocket,DatagramPackage针对直接URL的URL,URLConnection,HttpURLConnectionGoogle集成了Apache http客户端,这使得使用HTTP进行网络编程成为可能使用Web Service进行网络编程使用WebView视图组件显示网页


Web Service通过一种XML格式的特殊文件 来描述方法、参数、调用和返回值,这种格式的XML文件称为WSDL即Web服务描述语言。Web Service 采用的通信协议是SOAP,即简单对象访问协议,实现方式 KSOAPjar包

android提供了内置的浏览器,该浏览器使用了开源的Webkit引擎 ,使用浏览器需要通过WebView视图组件来实现WebView w=findViewById...String url="http://www.baidu.com";w.loadUrl(url);html="<a></a>"w.loadData(html,"text/html","utf-8");


原创粉丝点击