`
zhengdl126
  • 浏览: 2543143 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

picture_list

 
阅读更多

 

layout_picture_list.xml

 

 

 

 

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="@drawable/app_bg"

    android:orientation="vertical" >

 

    <ViewSwitcher

        android:id="@+id/viewswitcher_news_top"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_gravity="center" >

    </ViewSwitcher>

 

    <ListView

        android:id="@+id/picture_id"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:cacheColorHint="@color/transparent"

        android:divider="#00000000"

        android:listSelector="#00000000" />

 

</FrameLayout>

 

 

 

 

 

PictureListActivity.java

 

 

package com.cps.media.ui.picture;

 

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

 

import org.apache.http.HttpResponse;

import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.DefaultHttpClient;

import org.json.JSONArray;

import org.json.JSONObject;

 

import com.cps.media.R;

import com.cps.media.model.PictureItem;

import com.cps.media.util.CONST;

import com.cps.media.util.Util;

 

import android.app.Activity;

import android.content.Intent;

import android.graphics.Bitmap;

import android.net.Uri;

import android.os.AsyncTask;

import android.os.Bundle;

import android.os.Handler;

import android.util.Log;

import android.view.View;

import android.view.ViewGroup;

import android.widget.AdapterView;

import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.ViewSwitcher;

import android.widget.AdapterView.OnItemClickListener;

 

public class PictureListActivity extends Activity {

 

    private ListView mListView;

 

    private MyAdapter mAdapter;

 

    private List<PictureItem> mList;

   

    private ViewSwitcher viewSwitcher;

   

    private int mId;

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

       // TODO Auto-generated method stub

       super.onCreate(savedInstanceState);

       setContentView(R.layout.layout_picture_list);

 

       mListView = (ListView) findViewById(R.id.picture_id);

       mId = getIntent().getIntExtra("id", 1);

      

       viewSwitcher = (ViewSwitcher) findViewById(R.id.viewswitcher_news_top);

       viewSwitcher.addView(getLayoutInflater().inflate(

              R.layout.layout_progress_page, null));

      

       requestData();

    }

 

    private void requestData() {

       viewSwitcher.setVisibility(View.VISIBLE);

       viewSwitcher.showNext();

       Thread t = new Thread() {

           @Override

           public void run() {

              super.run();

              HttpClient client = new DefaultHttpClient();

              StringBuilder builder = new StringBuilder();

              int error = 1;

              JSONArray array = null;

              HttpGet myget = new HttpGet(CONST.URL_PICTURE_LIST.replace("{0}", mId+""));

 

              try {

                  HttpResponse response = client.execute(myget);

                  BufferedReader reader = new BufferedReader(

                         new InputStreamReader(response.getEntity()

                                .getContent()));

                  for (String s = reader.readLine(); s != null; s = reader

                         .readLine()) {

                     builder.append(s);

                  }

                  JSONObject jsonObject = new JSONObject(builder.toString());

                  error = jsonObject.getInt("errno");

                  String errormsg = jsonObject.getString("errmsg");

                  Log.v("wgp", "url=" + myget.getURI().toString());

                  Log.v("wgp", "error=" + error);

                  Log.v("wgp", "errormsg=" + errormsg);

                  if (error == 0) {

                     array = jsonObject.getJSONArray("data");

                     PictureItem item;

                     mList = new ArrayList<PictureItem>();

                     for (int i = 0; i < array.length(); i++) {

                         item = new PictureItem();

                         item.setId(array.getJSONObject(i).getInt("id"));

                         item.setTitle(array.getJSONObject(i).getString(

                                "title"));

                         item.setImgUrl(array.getJSONObject(i).getString(

                                "img"));

                         mList.add(item);

                     }

 

                     if (mList.size() == 0) {

                         handler.sendEmptyMessage(-1);

                     } else {

                         handler.sendEmptyMessage(1);

                     }

                  }

              } catch (Exception e) {

                  e.printStackTrace();

                  handler.sendEmptyMessage(-1);

              } finally {

 

              }

           }

       };

       t.start();

    }

 

    Handler handler = new Handler() {

 

       public void handleMessage(android.os.Message msg) {

           if (msg.what == 1) {

              mAdapter = new MyAdapter();

              mListView.setAdapter(mAdapter);

              mListView.setOnItemClickListener(mListItemListener);

           }

           viewSwitcher.setVisibility(View.INVISIBLE);

       }

    };

   

    private OnItemClickListener mListItemListener = new OnItemClickListener() {

 

       @Override

       public void onItemClick(AdapterView<?> parent, View view, int position,

              long id) {

           Intent intent = new Intent(Intent.ACTION_VIEW);

           intent.setDataAndType(Util.getHttpImageURI(mList.get(position).getImgUrl()), "image/*");

           startActivity(intent);

       }

 

    };

   

    class MyAdapter extends BaseAdapter {

      

       private AsyncImageTask mImageTask;

 

       @Override

       public int getCount() {

           // TODO Auto-generated method stub

           return mList.size();

       }

 

       @Override

       public Object getItem(int position) {

           // TODO Auto-generated method stub

           return mList.get(position);

       }

 

       @Override

       public long getItemId(int position) {

           // TODO Auto-generated method stub

           return mList.get(position).getId();

       }

 

       @Override

       public View getView(int position, View convertView, ViewGroup parent) {

           ViewHolder holder;

           if (convertView == null) {

              holder = new ViewHolder();

              convertView = getLayoutInflater().inflate(

                      R.layout.layout_picture_list_item, null);

              holder.tv_name = (TextView) convertView

                     .findViewById(R.id.name_id);

              holder.tv_image = (ImageView) convertView

                     .findViewById(R.id.type_image_id);

              convertView.setTag(holder);

           } else {

               holder = (ViewHolder) convertView.getTag();

           }

          

           mImageTask = new AsyncImageTask(holder.tv_image);

           mImageTask.execute(mList.get(position).getImgUrl());

          

           holder.tv_name.setText(mList.get(position).getTitle());

 

           return convertView;

       }

 

        class ViewHolder {

           TextView tv_name;

           ImageView tv_image;

           int type;

       }

      

       private class AsyncImageTask extends AsyncTask<String, Integer, Object> {

 

           private ImageView image;

 

           public AsyncImageTask(ImageView image) {

              this.image = image;

           }

 

           @Override

           protected Object doInBackground(String... params) {

              try {

                  if(Util.CPSE_CACHE.exists())

                     return Util.getHttpImageURI(params[0]);

                  else{

                     return Util.getHttpBitmap(params[0]);

                  }

              } catch (Exception e) {

                  // TODO: handle exception

              }

              return null;

           }

 

           @Override

           protected void onPostExecute(Object result) {

              // TODO Auto-generated method stub

              super.onPostExecute(result);

              if (image != null && result != null) {

                  if(result instanceof Uri){

                     image.setImageURI((Uri)result);

                  }else if(result instanceof Bitmap){

                     image.setImageBitmap((Bitmap)result);

                  }

              } else if (image != null && result == null) {

                  image.setImageResource(R.drawable.news_default);

              }

           }

 

       }

    }

 

}

 

 

 

 

 

 

 

 

 

 

  • 大小: 19.9 KB
分享到:
评论

相关推荐

    PictureList.rar_PICTURE CONTROL_control_list control_picturelist

    "PictureList.rar_PICTURE CONTROL_control_list control_picturelist"的标题和描述提示我们这是一个关于图片列表控制的资源包,包含实现该功能的源代码文件。 "Picture Control"是一种可以显示单个图像的控件,...

    picVote_picture_

    考虑到提供的标签为“picture”,我们可以推断这个系统可能用于评选最佳照片、图像或艺术作品等。 以下是一些相关的IT知识点: 1. **在线投票系统架构**:这类系统通常包括前端展示界面和后端处理逻辑。前端用于...

    文章频道图片模式浏览插件 for phpcms.rar

    picture.html和picture_list.html需要放到templates/当前所以模板目录/article下面 大功告成,可以浏览http://网址/文章频道目录/picture.php看看了 频道下的栏目,用http://网址/文章频道目录/picture.php?catid=...

    picture_gather_and_transport5.rar_Linux 图片

    `v4l2-ctl --list-devices`会列出所有可用的视频设备,而`v4l2-ctl --device /dev/videoX --stream-mmap=3 --stream-to=image.jpg`可以将设备/dev/videoX捕获的一帧图像保存为image.jpg。 此外,还可以使用开源库如...

    头像列表控件PictureList.OCX

    《头像列表控件PictureList.OCX详解》 在计算机编程领域,用户界面的设计是至关重要的,而头像列表控件(PictureList.OCX)则是实现个性化、直观交互的一种常见工具。本文将深入探讨这个控件的功能、用法以及它在...

    ListCtrl中插入图片,按钮,右键菜单,Edit控件等

    在MFC(Microsoft Foundation Classes)库中,ListCtrl是一个强大的控件,用于显示列式数据,它可以被扩展以实现各种自定义功能。本教程将详细讲解如何在ListCtrl中插入图片、按钮、颜色、Edit控件,以及添加右键...

    MFC在ListCtrl中加入Button

    在MFC(Microsoft Foundation Classes)框架中,ListCtrl是一个非常常用的控件,它通常用于显示列表数据,可以自定义列头、图标等。然而,仅靠ListCtrl本身的特性,我们无法直接在其中添加按钮。但是,通过一些技巧...

    Home-Assistant-Lovelace-HTML-Jinja2-Template-card:此卡将提供的Jinja2模板显示为卡HTML内容。 它使用与开发人员工具中的Home Assistant完全相同的引擎

    它使用与开发人员工具中的Home Assistant完全相同的引擎。...update boolean false false 启用每次实体更改时刷新卡的功能picture_elements_mode boolean false false 启用图片元素模式entities list f

    python tkiner实现 一个小小的图片翻页功能的示例代码

    具体代码如下所示: ... picture_list = [] for dir,dir_abs,files in os.walk(dirs): for file in files: if file.endswith('.gif'): picture_list.append(os.path.join(dir,file)) return pi

    基于Ant Design Upload listType=“picture-card“ 实现多图上传以及点击预览图片的组件

    在本文中,我们将深入探讨如何使用Ant Design库中的Upload组件,特别是当`listType`属性设置为`"picture-card"`时,实现一个功能完善的多图上传及预览功能。Ant Design是一个广泛使用的React UI框架,它提供了丰富的...

    access和tree和listctrl和picture和Button控件

    如果谁要用这个资源,请先把 CDemoDlg类中加的 头文件的 CStatic m_pot; 和 DDX_Control(pDX, IDC_BU_UPANDDOWN, m_pot); 删除,谢谢。或者全部重新编译

    picturelist.ocx

    头像列表控件。qq中的头像列表本控件实现一样的功能。你可以自由添加删除列表类,向列表类添加删除列表项,支持事件操作!可以定义列表类按钮正常、指向、鼠标按下时显示的图片,滚动条的图片

    picture.rar

    标题“picture.rar”暗示我们关注的是一个包含图片的RAR压缩文件。RAR是一种常见的文件压缩格式,用于存储多个文件和文件夹。在这个特定的例子中,它可能包含了一个或多个与OpenCV相关的图像,这些图像被用来演示...

    照相机相关1

    List&lt;Size&gt; supported = parameters.getSupportedPictureSizes(); String targetRatio = SettingChecker.getPreferenceValue(context, preferences, SettingChecker.ROW_SETTING_PICTURE_RATIO); Log.v(TAG, "target...

    dndbot

    通过输入+char add [name] [displayname] [picture_url]来创建+char add [name] [displayname] [picture_url]通过输入+char add [name] [displayname] [picture_url] npc创建npc +char add [name] [displayname] ...

    wen_ov5640_r16_20161114_1744后插入UVC可以打开ov5640和USB摄像头.7z

    verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_dev(x)_pos: sensor position, "rear" or "front", if vip_define_sensor_list = 1,vip_dev(x)_pos must be ...

    gc2145_parrotv1.1_r16m_验证完成_20170523_1408没有外层目录.7z

    struct sensor_item sensor_list_t[] = { // name i2c_addr sensor type sensor size sensor max pclk (请参照OV2640/GC2155配置) { "gc2145" , 0x78, SENSOR_YUV , PIXEL_NUM_2M , CORE_CLK_RATE_FOR_2M}, ...

    hm1375_sc3817r_sina33_rtl8188eu服务器验证通过20170621_1021没有外层目录.7z

    struct sensor_item sensor_list_t[] = { // name i2c_addr sensor type sensor size sensor max pclk { "hm1375" , 0x48, SENSOR_YUV , PIXEL_NUM_2M , CORE_CLK_RATE_FOR_2M}, { "hm5065" , 0x3e, SENSOR...

    gc2035_parrotv1.1_验证完成_vga+uxga_hd720p正常_svga_20171011_1725没有外层目录.7z

    verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_dev(x)_pos: sensor position, "rear" or "front", if vip_define_sensor_list = 1,vip_dev(x)_pos must be ...

Global site tag (gtag.js) - Google Analytics