substuting的android点击带有计时器

substuting的android点击带有计时器

本文介绍了substuting的android点击带有计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个例子,我有一个小问题:我如何删除上点击一个计时器或在此它显示的第一映像,并等待几秒钟,然后移动到下一个图像延迟

<$p$p><$c$c>http://mobile.dzone.com/news/displaying-images-sd-card?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+javalobby%2Ffrontpage+%28Javalobby+%2F+Java+Zone%29

感谢你。

 包blog.android.sdcard;

进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;
进口android.database.Cursor;
进口android.net.Uri;
进口android.os.Bundle;
进口android.provider.MediaStore;
进口android.view.Menu;
进口android.view.MenuInflater;
进口android.view.MenuItem;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.AdapterView;
进口android.widget.BaseAdapter;
进口android.widget.GridView;
进口android.widget.ImageView;
进口android.widget.AdapterView.OnItemClickListener;

/ **
 *从SD卡显示图像。
 * /
公共类SDCardImagesActivity延伸活动{

    / **
     *用游标从查询的图像在SD访问结果
     * 卡。
     * /
    私人光标指针;
    / *
     *为缩略图图像的ID列索引。
     * /
    私人诠释参数:columnIndex;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.sdcard);

        //设置我们想要的缩略图ID列的一个阵列
        的String []投影= {MediaStore.Images.Thumbnails._ID};
        //创建光标指向SD卡
        光标= managedQuery(
                MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,投影,//哪家
                                                                                //列
                                                                                // 至
                                                                                // 返回
                空,//返回所有行
                空,MediaStore.Images.Thumbnails.IMAGE_ID);
        //获取缩略图图片ID列索引
        参数:columnIndex =光标
                .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

        GridView控件sdcardImages =(GridView控件)findViewById(R.id.sdcard);
        sdcardImages.setAdapter(新ImageAdapter(本));

        //设置一个点击监听器
        sdcardImages.setOnItemClickListener(新OnItemClickListener(){
            公共无效onItemClick(适配器视图父,视图V,INT位置,
                    长ID){
                //获取图像的数据的位置
                的String []投影= {MediaStore.Images.Media.DATA};
                光标= managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        投影,//哪些列返回
                        空,//返回所有行
                        NULL,NULL);
                参数:columnIndex =光标
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToPosition(位置);
                //获取图像文件名
                字符串的ImagePath = cursor.getString(参数:columnIndex);
                //使用这个路径做进一步的处理,即全屏幕
                // 显示
            }
        });
    }

    / **
     *适配器为我们的图像文件。
     * /
    私有类ImageAdapter扩展了BaseAdapter {

        私人上下文的背景下;

        公共ImageAdapter(上下文localContext){
            上下文= localContext;
        }

        公众诠释getCount将(){
            返回cursor.getCount();
        }

        公共对象的getItem(INT位置){
            返回的位置;
        }

        众长getItemId(INT位置){
            返回的位置;
        }

        公共查看getView(INT位置,查看convertView,ViewGroup中父){
            ImageView的picturesView;
            如果(convertView == NULL){
                picturesView =新ImageView的(上下文);
                //将光标移动到当前位置
                cursor.moveToPosition(位置);
                //获取被请求的列的当前值
                INT imageID = cursor.getInt(参数:columnIndex);
                //设置基于所提供的URI的图像的内容
                picturesView.setImageURI(Uri.withAppendedPath(
                        MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                                + imageID));
                picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                picturesView.setPadding(8,8,8,8);
                picturesView
                        .setLayoutParams(新GridView.LayoutParams(100,100));
            } 其他 {
                picturesView =(ImageView的)convertView;
            }
            返回picturesView;
        }
    }
}
 

解决方案

无需线程。只需使用一个处理程序postDelayed消息...

 公共类的HelloHandler延伸活动{

保护处理程序处理程序=新的处理程序();

@覆盖
    公共无效的onCreate(包savedInstanceState){
       super.onCreate(savedInstanceState);
       // 等等等等等等

       handler.postDelayed(新UpdateTask(),500);
   }


   保护类UpdateTask实现Runnable {
   公共无效的run(){
      //做的东西。这是UI线程。
      handler.postDelayed(本,500);
   }
}
}
 

I found this example and i have a small question: How can I remove the on click to a timer or a delay where it displays the first image and waits a couple of seconds then moves to the next image?

http://mobile.dzone.com/news/displaying-images-sd-card?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+javalobby%2Ffrontpage+%28Javalobby+%2F+Java+Zone%29

Thank you.

package blog.android.sdcard;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * Displays images from an SD card.
 */
public class SDCardImagesActivity extends Activity {

    /**
     * Cursor used to access the results from querying for images on the SD
     * card.
     */
    private Cursor cursor;
    /*
     * Column index for the Thumbnails Image IDs.
     */
    private int columnIndex;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sdcard);

        // Set up an array of the Thumbnail Image ID column we want
        String[] projection = { MediaStore.Images.Thumbnails._ID };
        // Create the cursor pointing to the SDCard
        cursor = managedQuery(
                MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, // Which
                                                                                // columns
                                                                                // to
                                                                                // return
                null, // Return all rows
                null, MediaStore.Images.Thumbnails.IMAGE_ID);
        // Get the column index of the Thumbnails Image ID
        columnIndex = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

        GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
        sdcardImages.setAdapter(new ImageAdapter(this));

        // Set up a click listener
        sdcardImages.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position,
                    long id) {
                // Get the data location of the image
                String[] projection = { MediaStore.Images.Media.DATA };
                cursor = managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        projection, // Which columns to return
                        null, // Return all rows
                        null, null);
                columnIndex = cursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToPosition(position);
                // Get image filename
                String imagePath = cursor.getString(columnIndex);
                // Use this path to do further processing, i.e. full screen
                // display
            }
        });
    }

    /**
     * Adapter for our image files.
     */
    private class ImageAdapter extends BaseAdapter {

        private Context context;

        public ImageAdapter(Context localContext) {
            context = localContext;
        }

        public int getCount() {
            return cursor.getCount();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView picturesView;
            if (convertView == null) {
                picturesView = new ImageView(context);
                // Move cursor to current position
                cursor.moveToPosition(position);
                // Get the current value for the requested column
                int imageID = cursor.getInt(columnIndex);
                // Set the content of the image based on the provided URI
                picturesView.setImageURI(Uri.withAppendedPath(
                        MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""
                                + imageID));
                picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                picturesView.setPadding(8, 8, 8, 8);
                picturesView
                        .setLayoutParams(new GridView.LayoutParams(100, 100));
            } else {
                picturesView = (ImageView) convertView;
            }
            return picturesView;
        }
    }
}
解决方案

No need for threads. Just use a Handler with postDelayed messages...

public class HelloHandler extends Activity {

protected Handler handler = new Handler();

@Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // blah blah blah

       handler.postDelayed(new UpdateTask(),500);
   }


   protected class UpdateTask implements Runnable {
   public void run() {
      // Do stuff.  This is UI thread.
      handler.postDelayed(this, 500);
   }
}
}

这篇关于substuting的android点击带有计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:42