如何访问从SD卡的所有图像HTC Desire Z的 [英] How can access all images from sd card in HTC Desire Z

查看:103
本文介绍了如何访问从SD卡的所有图像HTC Desire Z的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示从SD卡HTC Desire Z的Andr​​oid行动的所有图像。我用这个网站的样本code

I am trying to show all images from SD card HTC desire Z Android Mobile. I use this websites sample code:

但音乐视频都是从标清访问card.but我无法显示图像。没有错误,没有错误。只显示黑屏。如何访问图像?

But Music Video all are access from SD card.but I am unable to show images. There is no Error,No bugs. Just show black screen. How can I access images?

任何一个可以有更好的主意。谁能给我一些示例code?

Any one can have better idea. Can anyone give me some sample code?

顺便提一下这个网站样本code是工作在另一个移动的罚款。我测试。

By the way this web sites sample code is working fine in another mobile. I test it.

请提供一些积极的引导。

Please provide some positive guide.

推荐答案

这是main.xml中

This is the main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:id="@+id/imageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitCenter"/>
    <TextView android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/imageView"
        android:layout_gravity="right|center_vertical"
        android:text="Next"
        android:textColor="@android:color/white"
        android:textSize="30sp"/>
    <TextView android:id="@+id/prev"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:text="Prev"
        android:textColor="@android:color/white"
        android:textSize="30sp"/>
</FrameLayout>

这是java文件

import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class DisplayAllImages extends Activity {
    ImageView mImageView;
    TextView mNext;
    TextView mPrev;
    Cursor mCursor;
    ArrayList list;
    int mIndex = 0;
    int mSize;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        mImageView = (ImageView)findViewById(R.id.imageView);
        mNext = (TextView)findViewById(R.id.next);
        mPrev = (TextView)findViewById(R.id.prev);
    }

    @Override
    protected void onResume() {
        mCursor = getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] {Media.DATA}, null, null, null);
        if(mCursor!=null && mCursor.moveToFirst()) {
            list = new ArrayList();
            mSize = mCursor.getCount();
            do {
                list.add(mCursor.getString(0));
            } while(mCursor.moveToNext());
            mImageView.setImageURI(Uri.parse(list.get(mIndex)));
        }
        mNext.bringToFront();
        mNext.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if(mIndex == (mSize-1)) {
                    mIndex = -1;
                }
                mImageView.setImageURI(Uri.parse(list.get(++mIndex)));
            }
        });
        mPrev.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if(mIndex == 0) {
                    mIndex = mSize;
                }
                mImageView.setImageURI(Uri.parse(list.get(--mIndex)));
            }
        });
        super.onResume();
    }
}

这篇关于如何访问从SD卡的所有图像HTC Desire Z的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆