当前位置:操作系统 > 安卓/Android >>

android imageswitcher gallery根据数据库内图片名字进行查看/删除

layout/imageswitch.xml
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageSwitcher
        android:id="@+id/arc_hf_img_switcher"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:gravity="center" >

        <Gallery
            android:id="@+id/arc_hf_img_gallery"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            android:layout_weight="1"
            android:background="#55000000"
            android:gravity="center_vertical"
            android:spacing="16dp" />

        <Button
            android:id="@+id/arc_hf_img_btnDel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="30dp"
            android:text="@string/arc_hf_img_btnDel" />

        <Button
            android:id="@+id/arc_hf_img_btnBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="30dp"
            android:text="@string/arc_hf_img_btnBack" />
    </LinearLayout>

</RelativeLayout>
 
ImgSwitch.java
 
public class ImgSwitch extends Activity implements OnItemSelectedListener,
        ViewFactory {
    private final String DATABASE_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath() + "/hfdatabase";
    private final String DATABASE_FILENAME = "hf_database.db";
    private final String TABLE_NAME = "HF_IMG_THEME";
    private final String strImgPath = Environment.getExternalStorageDirectory()
            .toString() + "/dlion/";// 存放照片的文件夹
    private SQLiteDatabase db;
    private ImageSwitcher is;
    private Gallery gallery;
    private Bitmap[] bitmaps;
    private int[] _ids;
    private String[] imgNames;
    private int parentId;
    public int gPosition = 0;
    private int isPosition = 0;
    private Button btnDel;
    private Button btnBack;

    // 返回键监听,添加关闭数据库功能。
    public void onBackPressed() {
        super.onBackPressed();
        db.close();
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imageswitch);
        db = openDatabase();
        parentId = this.getIntent().getIntExtra("parentId", 0);

        gallery = (Gallery) findViewById(R.id.arc_hf_img_gallery);
        is = (ImageSwitcher) findViewById(R.id.arc_hf_img_switcher);
        is.setFactory(this);

        is.setInAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in));
        is.setOutAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out));

        btnDel = (Button) findViewById(R.id.arc_hf_img_btnDel);
        btnBack = (Button) findViewById(R.id.arc_hf_img_btnBack);
        btnDel.setOnClickListener(new btnListener());
        btnBack.setOnClickListener(new btnListener());

        initImgs();
    }

    // 按键监听
    class btnListener implements OnClickListener {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
            case R.id.arc_hf_img_btnBack:
                db.close();
           &n

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,