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. Azkaban 2.5.0 搭建

    一.前言 最近试着参照官方文档搭建 Azkaban,发现文档很多地方有坑,所以在此记录一下. 二.环境及软件 安装环境: 系统环境: ubuntu-12.04.2-server-amd64 安装目录: ...

  2. CSS中文字体对照表

    http://hotoo.googlecode.com/svn/trunk/labs/css/css-fonts.html CSS中文字体对照表 css字体名可以使用2种Unicode格式,以“微软雅 ...

  3. 据说最近IMO中国队失利的一题

    (图基于Microsoft PaintBrush技术构建) 平面几何是可以难得出蛆的.这道题难在多圆.高度非对称和具有一定复杂性.如图,对ABC,H是垂心,O是垂足,M是中点.QK在ABC外接圆上,均 ...

  4. require.js 入门学习 (share)

    以下内容转自阮一峰老师的网络日志:http://www.ruanyifeng.com/blog/2012/11/require_js.html 更多学习资源: require.js官网:http:// ...

  5. 自己收集原生js-2014-2-23

    (function(){})( window.EventUtil={ addHandler:function(element,type,handler){ // alert(1); if(elemen ...

  6. SRM 615 DIV1 500

    TC 都615了...时间过的真快啊. 第一次做出500分,心情还是很激动的,虽然看了很久的题解,TC官网上的题解,很详细,但是英语的...我搜了搜,发现一份日语的...好吧,我还是看看英语的吧... ...

  7. CF 16C. Monitor

    题目链接 水题依旧无法1Y. #include <cstdio> #include <iostream> #include <cmath> using namesp ...

  8. URAL 1501. Sense of Beauty(记忆化搜索)

    题目链接 本来暴力写个TLE了,加上记忆化就A了. #include <cstring> #include <cstdio> #include <string> # ...

  9. Linux 获取设备树源文件(DTS)里描述的资源

    Linux 获取设备树源文件(DTS)里的资源 韩大卫@吉林师范大学 在linux使用platform_driver_register() 注册 platform_driver 时, 需要在 plat ...

  10. IOS 蓝牙相关-连接外设的代码实现(2)

    我们具体说明一下中心模式的应用场景.主设备(手机去扫描连接外设,发现外设服务和属性,操作服务和属性的应用.一般来说,外设(蓝牙设备,比如智能手环之类的东西), 会由硬件工程师开发好,并定义好设备提供的 ...