package com.ali.fridge.supermarket.module;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView; import com.ali.fridge.R;
import com.ali.fridge.util.LogUtils; import java.util.List; import static com.ali.fridge.util.LogUtils.makeLogTag; /**
* Created by xiaomin.wxm on 2016/4/7.
*/
public class MyArrayAdapter extends ArrayAdapter<String> { private static final String TAG = makeLogTag(MyArrayAdapter.class);
private Context mContext;
private List<String> mString;
private LayoutInflater mInflater;
private boolean mFirst = true;
private int mNowItemSelected;
private MyViewHolder holder; public MyArrayAdapter(Context context, int textViewResourceId, List<String> aStrings) {
super(context, textViewResourceId, aStrings);
mString = aStrings;
mContext = context;
/*if (mString == null) {
mString = new ArrayList<>();
mString.add("推荐");
}*/
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new MyViewHolder();
mInflater = LayoutInflater.from(mContext);
convertView = mInflater.inflate(R.layout.goods_item_onecategory, null);
holder.categoryName = (TextView) convertView.findViewById(R.id.goods_tv_category);
holder.ivVerticalBar = (ImageView) convertView.findViewById(R.id.goods_img_category_selector);
convertView.setTag(holder);
} else {
holder = (MyViewHolder) convertView.getTag();
}
holder.categoryName.setText(mString.get(position));
if (position == mNowItemSelected) {
holder.ivVerticalBar.setVisibility(View.VISIBLE);
} else {
holder.ivVerticalBar.setVisibility(View.GONE);
}
return convertView;
} public void setNewData(List<String> aStrings) {
LogUtils.LOGD(TAG, "setNewData begin");
clear();
mString = aStrings;
/*if (mString == null) {
mString = new ArrayList<>();
mString.add("推荐");
}*/
if (mString != null) {
for (int i = 0; i < mString.size(); i++) {
insert(mString.get(i), i);
}
}
notifyDataSetChanged();
LogUtils.LOGD(TAG, "setNewData end");
} /*
index : selectitem index <0 means not selected
*/
public void setSelected(int index) {
mNowItemSelected = index;
notifyDataSetChanged();
} private class MyViewHolder {
TextView categoryName;
ImageView ivVerticalBar;
}
}

MyArrayAdapter 比较标准的写法的更多相关文章

  1. MSSQL 标准PROC 写法

    MSSQL 标准PROC 写法 ALTER PROC [dbo].[usp_ADM_InsertFlowSortInfo]@FlowSortName NVARCHAR(50),AS/*PAGE: 分类 ...

  2. try catch finally 关闭流标准的写法

    平常开发中,都知道要在finlly里关闭流,但是有时finlly里代码不当,会引起另外的异常. 以下是看struts2源代码看到的,随手记录下. 有两点注意: (1)判断流是否为空. (2)filly ...

  3. Java 标准DBUtil 写法

    package xueruan.com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql ...

  4. jquery Ajax标准规范写法

    $.ajax({ url:"http://www.xxx",//请求的url地址 dataType:"json",//返回的格式为json async:true ...

  5. ViewHolder的标准写法

    最标准的写法,就是为每一个AdapterView的子View新建一个对应的ViewHolder,同时声明为prtivate final static.ViewHolder类中定义各种成员变量. pub ...

  6. 从IntToHex()说起,栈/堆地址标准写法 good

    学习中的一些牢骚.栈/堆地址标准写法. 2017-02-12 • 杂谈 • 暂无评论 • 老衲 •浏览 226 次 我一直都在寻找各种业务功能的最简单写法,用减法的模式来开发软件.下面是我的写法,如果 ...

  7. (转)Css样式兼容IE6,IE7,FIREFOX的写法

    根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF:          background:orange;*background:blue;   区别I ...

  8. node.js 标准/错误输出 和 process.exit

    node.js中,各种模块有一种标准的写法: this._process.exec(command, options, function (err, stdout, stderr) { callbac ...

  9. Css样式兼容IE6,IE7,FIREFOX的写法

    根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF:          background:orange;*background:blue;   区别I ...

随机推荐

  1. Android service介绍和启动方式

    1.Android service的作用: service通常是用来处理一些耗时操作,或后台执行不提供用户交互界面的操作,例如:下载.播放音乐. 2.Android service的生命周期: ser ...

  2. 实战Hadoop中遇到的几个类、接口说明

    1. Configuration :public 类型接口,这个接口包含的多数方法是进行与数据属性<key,value>有关的操作. 几个方法: 1)addProperty(String ...

  3. Codeforces 567C Geometric Progression(思路)

    题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...

  4. Storm中Spout使用注意事项小结

    Storm中Spout用于读取并向计算拓扑中发送数据源,最近在调试一个topology时遇到了系统qps低,处理速度达不到要求的问题,经过排查后发现是由于对Spout的使用模式不当导致的多线程同步等待 ...

  5. yarn map failed

    Container launch failed for container_1385017085286_4943_01_000053 : org.apache.hadoop.yarn.exceptio ...

  6. HDU 1686 & KMP

    题意: 求模板在匹配串所有子串中出现次数. SOL: 本题与普通kmp有一点不同,因为待匹配串中的模板串可能相互包含. 我们考虑正常的kmp是在怎么做的 i = 1 2 3 4 5 6 7 8 9 … ...

  7. reason: '*** Collection <__NSCFArray: 0x7ffa43528f70> was mutated while being enumerated.'

    一,错误分析 1.崩溃代码如下: //遍历当前数组,判断是否有相同的元素 for (NSString *str in self.searchHistoryArrM) { if ([str isEqua ...

  8. get,post 区别,HTTP通信

    GET & POST GET      1.GET 的本质是"得"      2.从服务器拿数据,效率更高 3.从数学的角度来讲,GET 的结果是"幂等" ...

  9. 20145330第七周《Java学习笔记》

    20145330第七周<Java学习笔记> 第十三章 时间与日期 认识时间与日期 时间的度量 GMT(格林威治标准时间):现在不是标准时间 世界时(UT):1972年UTC出来之前,UT等 ...

  10. Centos Odoo Service Config

    #!/bin/sh ### BEGIN INIT INFO # Provides: openerp-server # Required-Start: $remote_fs $syslog # Requ ...