WEB开发网
开发学院手机开发Android 开发 如何实现一个基本的Android用户界面 阅读

如何实现一个基本的Android用户界面

 2010-06-12 20:06:00 来源:WEB开发网   
核心提示:this,R.array.colors,android.R.layout.simple_spinner_item);adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);s1.setAdapter(adapter);

this,R.array.colors,android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

s1.setAdapter(adapter);

//LoadaSpinnerandbindittoadataquery.

privatestaticString[]PROJECTION=newString[]{

People._ID,People.NAME

};

Spinners2=(Spinner)findViewById(R.id.spinner2);

Cursorcur=managedQuery(People.CONTENT_URI,PROJECTION,null,null);

SimpleCursorAdapteradapter2=newSimpleCursorAdapter(this,

android.R.layout.simple_spinner_item,//Useatemplate

//thatdisplaysa

//textview

cur,//Givethecursortothelistadatper

newString[]{People.NAME},//MaptheNAMEcolumninthe

//peopledatabaseto...

newint[]{android.R.id.text1});//The"text1"viewdefinedin

//theXMLtemplate

adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

s2.setAdapter(adapter2);

注意:使用CursorAdapter时,必须有People._ID,否则将会发生异常。

处理用户操作Android通过设置类的AdapterView.OnItemClickListener成员到一个监听者并捕捉用户的操作事件,来处理用户的操作。

//Createamessagehandlingobjectasananonymousclass.

privateOnItemClickListenermMessageClickedHandler=newOnItemClickListener(){

publicvoidonItemClick(AdapterViewparent,Viewv,intposition,longid)

{

//Displayamessagebox.

showAlert("You'vegotanevent","Clickedme!","ok",false);

}

};

//NowhookintoourobjectandsetitsonItemClickListenermember

//toourclasshandlerobject.

mHistoryView=(ListView)findViewById(R.id.accept_button);

mHistoryView.setOnItemClickListener(mMessageClickedHandler);

上一页  1 2 3 4 5 6 

Tags:如何 实现 一个

编辑录入:coldstar [复制链接] [打 印]
赞助商链接