WEB开发网
开发学院手机开发Android 开发 Android 用户界面详解 阅读

Android 用户界面详解

 2010-02-22 17:09:00 来源:WEB开发网   
核心提示:};Spinner s2 = (Spinner) findViewById(R.id.spinner2);Cursor cur = managedQuery(People.CONTENT_URI, PROJECTION, null, null);SimpleCursorAdapter adapter2 = new Si

};

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

Cursor cur = managedQuery(People.CONTENT_URI, PROJECTION, null, null);

SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this,

android.R.layout.simple_spinner_item, // Use a template

// that displays a

// text view

cur, // Give the cursor to the list adatper

new String[] {People.NAME}, // Map the NAME column in the

// people database to...

new int[] {android.R.id.text1}); // The "text1" view defined in

// the XML template

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

s2.setAdapter(adapter2);

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

处理用户操作

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

// Create a message handling object as an anonymous class.

private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {

public void onItemClick(AdapterView parent, View v, int position, long id)

{

// Display a messagebox.

showAlert("You've got an event", "Clicked me!", "ok", false);

}

};

// Now hook into our object and set its onItemClickListener member

// to our class handler object.

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

mHistoryView.setOnItemClickListener(mMessageClickedHandler);

上一页  3 4 5 6 7 8 

Tags:Android 用户界面 详解

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