Android中的动态图像显示

Android中的动态图像显示,android,image,Android,Image,我需要有一个文件夹的图像下载。然后遍历该文件夹的内容,在预设的时间段内逐个显示图像。我的屏幕分为三个部分: 在第一行中,有两列:列表视图和图像视图 第二行有一个图像视图 我的重点是显示图像。我的问题是如何创建图像视图,因为图像资源不在Android的res文件夹中,它是在运行时确定的。我无法使用android:src=“@drawable/android”标记将图像放入图像视图 我运行了调试器,但控件没有进入if(file.isDirectory())块。我在H://电话卡中有一个名为Ser

我需要有一个文件夹的图像下载。然后遍历该文件夹的内容,在预设的时间段内逐个显示图像。我的屏幕分为三个部分:

  • 在第一行中,有两列:列表视图和图像视图
  • 第二行有一个图像视图
我的重点是显示图像。我的问题是如何创建图像视图,因为图像资源不在Android的res文件夹中,它是在运行时确定的。我无法使用
android:src=“@drawable/android”
标记将图像放入图像视图

我运行了调试器,但控件没有进入
if(file.isDirectory())
块。我在
H://
电话卡中有一个名为
ServiceMobile2
的文件夹

<-xml file->
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:stretchColumns="*" android:background="#ffffff">
    <!-- Row 1 with single column -->
     <TableRow
         android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal">
    <EditText
    android:id="@+id/personal_contacts"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:hint="number"
    android:inputType="number"
    android:imeOptions="actionSend" />
    <TableRow
         android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal">
     <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Save" />
     </TableRow>
      <TableRow
         android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal">
    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Delete" />
    </TableRow>
    </TableRow>
    <TableRow
         android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal">
      <ListView
        android:id="@+id/list2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView> 
      <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

     </TableRow>  
         <TableRow
         android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal">
      <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
      </TableRow> 
    </TableLayout>


public void getFromSdcard()
{   
    File file=  new File(android.os.Environment.getExternalStorageDirectory(),"serviceMobile2");
    Toast.makeText(getBaseContext(), "file printer",Toast.LENGTH_SHORT).show();
    if (file.isDirectory())
    {
        listFile = file.listFiles();

        for (int i = 0; i < listFile.length; i++)
        {
            mFileStrings[i] = listFile[i].getAbsolutePath();
            f.add(listFile[i].getAbsolutePath());
            System.out.println("...................................."+mFileStrings[i]);
            Toast.makeText(getBaseContext(), mFileStrings[i], Toast.LENGTH_SHORT).show();
            Bitmap bitmap = BitmapFactory.decodeFile(listFile[i].getAbsolutePath());
            ImageView iv= (ImageView) findViewById(R.id.imageView2);
            iv.setImageBitmap(bitmap);
        }
    }
}

public void getFromSdcard()
{   
File File=新文件(android.os.Environment.getExternalStorageDirectory(),“serviceMobile2”);
Toast.makeText(getBaseContext(),“文件打印机”,Toast.LENGTH_SHORT.show();
if(file.isDirectory())
{
listFile=file.listFiles();
for(int i=0;i
问题出在哪里?您应该从保存图像的内存中加载图像。。上述问题可能与链接中的问题有关。如果您得到一个例外,请提供logcat详细信息。因此,您的问题是为什么在您的程序中不返回
file.isDirectory()
return
true
serviceMobile2
是sd卡上的一个目录吗?如果(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){do something}检查sd卡是否已安装我的手机上只显示一个内存H:/phone memory