WEB开发网
开发学院手机开发Android 开发 Android 模拟器操作演练 阅读

Android 模拟器操作演练

 2010-02-20 17:15:00 来源:WEB开发网   
核心提示:import android.database.Cursor;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.ListView;import android.widget.Sim

import android.database.Cursor;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.ListView;

import android.widget.SimpleAdapter;

public class ac01 extends ListActivity {

public static int g_variable;

public static final String AUTHORITY = "com.misoo.provider.rx09-02";

public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY

+ "/Student");

private static final String[] PROJECTION

= new String[]{ "stud_no", "stud_name"};

@Override protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Intent intent = getIntent();

if (intent.getData() == null) intent.setData(CONTENT_URI);

Cursor cur = getContentResolver().query(getIntent().getData(),

PROJECTION, null, null, null);

ArrayList> coll = new ArrayList>();

Map item;

cur.moveToFirst();

while (!cur.isAfterLast()) {

item = new HashMap();

item.put("c1", cur.getString(0) + ", " + cur.getString(1));

coll.add(item);

cur.moveToNext();

}

this.setListAdapter(new SimpleAdapter(this, coll,

android.R.layout.simple_list_item_1, new String[] { "c1" },

new int[] { android.R.id.text1 }));

}

@Override

protected void onListItemClick(ListView l, View v, int position, long id) { finish();}

}

指令:

Cursor cur = getContentResolver().query(getIntent().getData(),

PROJECTION, null, null, null);

要求Android代为寻找适合的ContentProvider来提供服务,并不刻意指定由DataProvider物件来担任。只要合乎ConentProvider介面,且符合意图条件的物件皆可以来为ac01物件提供服务。于是,ac01程式码就不再直接呼叫DataProvider类别的函数了,而是呼叫ContentProvider介面所提供的函数。再来仔细看看DataProvider类别与ContentProvider介面的搭配情形:

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Android 模拟器 操作

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