如何使从网页文本框和ImageView的自定义列表适配器? [英] How to make a custom list adapter with textbox and imageview from web?

查看:95
本文介绍了如何使从网页文本框和ImageView的自定义列表适配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用,我通过跑的AsyncTask获取(GET)一些信息,当用户给出一个TextBox一些信息并点击了按钮,启动任务参数乌里链接。

I'm using a parameterized Uri link that I ran through AsyncTask to acquire(GET) some info whenever the user gives some info in a TextBox and hits the Button to start the task.

我得到的响应,并插入信息作为的JSONObject并把它放到一个HashMap的ArrayList中,由三个字段,全名,用户名和PhotoByte。

I get the response and insert that info as JSONObject and put it into an ArrayList of HashMap that consists three fields, fullname, username and the PhotoByte.

我要的就是让为ListView自定义适配器,以显示这些信息。我知道如何反codeByteArray的位图,并将其设置为一个ImageView的地方,但我挣扎。

What I want is to make a custom adapter for the ListView in order to display that info. I know how to decodeByteArray to a Bitmap and set it to an ImageView but somewhere I'm struggling.

我跟着这个教程如何使自定义适配器是好的......但我并不需要实例HttpConnections无论是我需要从URL加载图像,而不是我需要转换从URL中给出的字节数组,并显示在内部的ImageView的该自定义适配器的ListView项。

I followed this tutorial on how to make a custom adapter which is Ok...but I don't need to instantiate HttpConnections neither I need to load image from url, instead I need to convert byteArray given from the url and show it in the ImageView within the ListView item of that custom adapter.

推荐答案

是使用自定义适配器,它里面你可以做任何你喜欢的;)下面是一些code,但你也许应该看看其他例子弄清楚适配器是如何工作的。

yes use a custom adapter, inside it you can do whatever you like ;) Here is some code, but you should maybe look at other examples to figure out how an adapter works.

>      public class Adapter_Custom extends BaseAdapter {
>         
>           // DEBUG
>           private final String TAG = this.getClass().getSimpleName();
>         
>           // Layout
>           private LayoutInflater inflater = null;
>           public ViewHolder holder;
>           View vi;
>         
>           Context context;
>           private ArrayList<Item_Pin> pinItems;
>         
>           public Adapter_Custom(Context context, ArrayList<Item_Pin> pinItems) {
>               this.context    = context;
>               this.pinItems   = pinItems;
>               
>               inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>           }
>         
>           // Used internally by this class
>           public int getCount() {
>               return pinItems.size();
>           }
>           
>           // 
>           @Override
>           public long getItemId(int position) {
>               // Return whatever u like here
>               return 0;
>           }
>         
>           @Override
>           public String getItem(int position) {
>               return "You can return whatever u like here";
>           }
>         
>           public View getView(int position, View convertView, ViewGroup parent) {
>         
>               vi = convertView;
>          // If there is no ViewHolder already, create a new one
>               if(convertView  ==  null){
>                   vi = inflater.inflate(R.layout.your_xml_file, null);
>                   holder = new ViewHolder();
>         
>                   holder.title        = (TextView)vi.findViewById(R.id.your_xml_file_textview);
>                   holder.background   = (LinearLayout)vi.findViewById(R.id.your_xml_file_linearlayout);
>         
>                   vi.setTag(holder);
>                   holder = (ViewHolder)vi.getTag(); // If there already is a viewholder, reuse it!                 
} else {
>                   holder = (ViewHolder)vi.getTag();
>               }
>          // This is where you place code for every list item - this is where you convert your base64 to images.
>               holder.title.setText(pinItems.get(position).getPinText());
>               // here you could also set the background of holder.background to your base64 image.
>         
>               return vi;
>           }
>         
>           //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>           // VIEWHOLDER - This is the code part of your XML
>           //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>           public class ViewHolder{
>         
>               public TextView title;
>               public LinearLayout background;
>         
>           }
>         }

使用了code并用自己的XML文件和数据替换它,那么干脆把code。在您的字节数组转换为图像的每一个列表项getView()方法。

Use that code and replace it with your own XML file and data, then simply put code in the getView() method that converts your byte arrays to images for every list item.

这篇关于如何使从网页文本框和ImageView的自定义列表适配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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