import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DictionaryOpenHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 2;
private static final String DICTIONARY_TABLE_NAME = " user ";
private static final String DICTIONARY_TABLE_CREATE =
"CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +
"id" + " int, " +
"name" + " TEXT);";
DictionaryOpenHelper(Context context) {
super(context, "airib_database", null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// db.execSQL(DICTIONARY_TABLE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2)
{
}
}
package fil.ted.test;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.util.Log;
public class TestDAO
{
public static String getString(Activity activity)
{
// StringBuffer strBuf = new StringBuffer(Environment.getDataDirectory().toString());
// strBuf.append("/data/data/");
// strBuf.append("fil.ted.test");
//
// strBuf.append("/databases/");
// strBuf.append("air");
// String dbPath = strBuf.toString();
// SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
// db.execSQL("select id from airib");
DictionaryOpenHelper mDbHelper= new DictionaryOpenHelper(activity);
SQLiteDatabase db = mDbHelper.getReadableDatabase();
String [] strr ={"id","name"};
Cursor cursor = db.query("user", strr,
null, null, null, null, null);
//return cursor.toString();
String str = "start---";
if(cursor.moveToFirst()){
do{
str = str+cursor.getString(0)+cursor.getString(1)+""t";
}while(cursor.moveToNext());
}
return str;
}
/**
* @param args
*/
public static void main(String[] args)
{
System.out.println(12);
}
}
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
//定义Context,即Activity
private Context context;
//定义整型数组 即图片源。
private Integer image[]
=
{
R.drawable.add_symbol,
R.drawable.delete_icon,
R.drawable.delete_key,
R.drawable.neato,
R.drawable.plus,
R.drawable.igoogle_logo_sm
};
public ImageAdapter(Context c) throws IllegalArgumentException, IllegalAccessException{
context=c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
//获取图片个数。
return Integer.MAX_VALUE;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
//获取图片在库中的位置。
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
//获取图片在库中的位置。
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageview=new ImageView(context);
//给imageView设置图片资源。
imageview.setImageResource(image[position%image.length]);
//设置比例类型。
imageview.setScaleType(ImageView.ScaleType.FIT_XY);
//设置图片布局和显示大小。
imageview.setLayoutParams(new Gallery.LayoutParams(100,100));
//设置图片之间的距离。
imageview.setPadding(15,0,15,0);
return imageview;
}
}
setContentView(R.layout.main);
// 初始化Gallery。
gallery = (Gallery) findViewById(R.id.gallery);
try
{
// 设置Gallery的Adapter。
gallery.setAdapter(new ImageAdapter(TestAndroidActivity.this));
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// 点击事件。
gallery.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView arg0, View arg1, int itemid, long arg3)
{
// TODO Auto-generated method stub
setTitle("您点击了第" + String.valueOf(itemid + 1) + "项");
}
});
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margintop="30dp">
</gallery>
</linearlayout>