Android 从应用框架角度看ListView与Adapter类别
2010-06-01 15:48:00 来源:WEB开发网于此,请看一个简单的Android程序代码,来体会上述智慧会合的实现。此程序的画面显示一个单纯的文字List窗口:
其程序代码如下:
复制到剪贴板 Java代码
/* ac01.java */
package xom.misoo.pkzz;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class ac01 extends Activity implements OnItemClickListener {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ListView lv = new ListView(this);
lv.setAdapter(new myAdapter(this));
lv.setOnItemClickListener(this);
setContentView(lv);
}
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
if(arg2 == 0)
setTitle(((TextView)arg1).getText());
else if(arg2 == 1)
finish();
}
}
/* myAdapter.java */
package xom.misoo.pkzz;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class myAdapter extends BaseAdapter {
private Context ctx;
private ArrayList
public myAdapter(Context context) {
ctx = context;
coll = new ArrayList
更多精彩
赞助商链接