您的位置:首页 > 其它

多级下拉列表选择处理

2016-05-27 16:58 435 查看




public class MainActivity extends Activity {

private Context context;

private ListView mListView, mShoplist_threelist, mShoplist_onelist2,

mShoplist_twolist2, mShoplist_onelist1, mShoplist_twolist1;

private LinearLayout mShoplist_mainlist2, mShoplist_mainlist1;

private TextView mShoplist_title_textbtn1, mShoplist_title_textbtn2,

mShoplist_title_textbtn3;

private SearchMoreAdapter threeadapter = null;

private SearchMoreAdapter twoadapter1 = null;

private SearchMainAdapter oneadapter1 = null;

private SearchMoreAdapter twoadapter2 = null;

private SearchMainAdapter oneadapter2 = null;

private boolean threelistview = false;

private boolean mainlistview1 = false;

private boolean mainlistview2 = false;

private List<Map<String, Object>> mainList1;

private List<Map<String, Object>> mainList2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initView();

context=this;

setpagedata();

}

private void setpagedata() {

// TODO Auto-generated method stub

initModel1();

initModel2();

oneadapter1 = new SearchMainAdapter(context, mainList1,R.layout.shop_list1_item,false);

oneadapter1.setSelectItem(0);

mShoplist_onelist1.setAdapter(oneadapter1);

oneadapter2 = new SearchMainAdapter(context, mainList2,R.layout.shop_list1_item,true);

oneadapter2.setSelectItem(0);

mShoplist_onelist2.setAdapter(oneadapter2);

threeadapter = new SearchMoreAdapter(context,Model.SHOPLIST_THREELIST,R.layout.shop_list2_item);

mShoplist_threelist.setAdapter(threeadapter);

initAdapter1(Model.SHOPLIST_PLACESTREET[0]);

initAdapter2(Model.MORELISTTXT[0]);

Onelistclick1 onelistclick1 = new Onelistclick1();

Twolistclick1 twolistclick1 = new Twolistclick1();

Onelistclick2 onelistclick2 = new Onelistclick2();

Twolistclick2 twolistclick2 = new Twolistclick2();

ThreeListOnItemclick threeListOnItemClick = new ThreeListOnItemclick();

mShoplist_onelist1.setOnItemClickListener(onelistclick1);

mShoplist_twolist1.setOnItemClickListener(twolistclick1);

mShoplist_onelist2.setOnItemClickListener(onelistclick2);

mShoplist_twolist2.setOnItemClickListener(twolistclick2);

mShoplist_threelist.setOnItemClickListener(threeListOnItemClick);

}

private void initModel1() {

mainList1 = new ArrayList<Map<String, Object>>();

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

Map<String, Object> map = new HashMap<String, Object>();

map.put("txt", Model.SHOPLIST_PLACE[i]);

mainList1.add(map);

}

}

private void initModel2() {

mainList2 = new ArrayList<Map<String, Object>>();

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

Map<String, Object> map = new HashMap<String, Object>();

map.put("img", Model.LISTVIEWIMG[i]);

map.put("txt", Model.LISTVIEWTXT[i]);

mainList2.add(map);

}

}

private void initAdapter1(String[] array) {

twoadapter1 = new SearchMoreAdapter(context, array,R.layout.shop_list2_item);

mShoplist_twolist1.setAdapter(twoadapter1);

twoadapter1.notifyDataSetChanged();

}

private void initAdapter2(String[] array) {

twoadapter2 = new SearchMoreAdapter(context, array,R.layout.shop_list2_item);

mShoplist_twolist2.setAdapter(twoadapter2);

twoadapter2.notifyDataSetChanged();

}

private void initView() {

// TODO Auto-generated method stub

mShoplist_title_textbtn1 = (TextView) findViewById(R.id.Shoplist_title_textbtn1);

mShoplist_title_textbtn2 = (TextView) findViewById(R.id.Shoplist_title_textbtn2);

mShoplist_title_textbtn3 = (TextView) findViewById(R.id.Shoplist_title_textbtn3);

mShoplist_mainlist1 = (LinearLayout) findViewById(R.id.Shoplist_mainlist1);

mShoplist_mainlist2 = (LinearLayout) findViewById(R.id.Shoplist_mainlist2);

mShoplist_onelist1 = (ListView) findViewById(R.id.Shoplist_onelist1);

mShoplist_twolist1 = (ListView) findViewById(R.id.Shoplist_twolist1);

mShoplist_onelist2 = (ListView) findViewById(R.id.Shoplist_onelist2);

mShoplist_twolist2 = (ListView) findViewById(R.id.Shoplist_twolist2);

mShoplist_threelist = (ListView) findViewById(R.id.Shoplist_threelist);

MyOnclickListener mOnclickListener = new MyOnclickListener();

mShoplist_title_textbtn1.setOnClickListener(mOnclickListener);

mShoplist_title_textbtn2.setOnClickListener(mOnclickListener);

mShoplist_title_textbtn3.setOnClickListener(mOnclickListener);

}

private class Onelistclick1 implements OnItemClickListener {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

initAdapter1(Model.SHOPLIST_PLACESTREET[arg2]);

oneadapter1.setSelectItem(arg2);

oneadapter1.notifyDataSetChanged();

}

}

private class Twolistclick1 implements OnItemClickListener {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

twoadapter1.setSelectItem(arg2);

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn1.setCompoundDrawables(null, null, drawable,

null);

int position = oneadapter1.getSelectItem();

mShoplist_title_textbtn1

.setText(Model.SHOPLIST_PLACESTREET[position][arg2]);

mShoplist_mainlist1.setVisibility(View.GONE);

mainlistview1 = false;

}

}

private class Onelistclick2 implements OnItemClickListener {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

initAdapter2(Model.MORELISTTXT[arg2]);

oneadapter2.setSelectItem(arg2);

oneadapter2.notifyDataSetChanged();

}

}

private class Twolistclick2 implements OnItemClickListener {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

twoadapter2.setSelectItem(arg2);

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn2.setCompoundDrawables(null, null, drawable,

null);

int position = oneadapter2.getSelectItem();

mShoplist_title_textbtn2.setText(Model.MORELISTTXT[position][arg2]);

mShoplist_mainlist2.setVisibility(View.GONE);

mainlistview2 = false;

}

}

private class ThreeListOnItemclick implements OnItemClickListener {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,

long arg3) {

threeadapter.setSelectItem(arg2);

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn3.setCompoundDrawables(null, null, drawable,

null);

mShoplist_title_textbtn3.setText(Model.SHOPLIST_THREELIST[arg2]);

mShoplist_threelist.setVisibility(View.GONE);

threelistview = false;

}

}

private class MyOnclickListener implements View.OnClickListener {

public void onClick(View v) {

int mID = v.getId();

if (mID == R.id.Shoplist_title_textbtn3) {

Drawable drawable = null;

if (!threelistview) {

drawable = getResources().getDrawable(

R.drawable.ic_arrow_up_black);

mShoplist_threelist.setVisibility(View.VISIBLE);

threeadapter.notifyDataSetChanged();

threelistview = true;

} else {

drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

mShoplist_threelist.setVisibility(View.GONE);

threelistview = false;

}

// 这一步必须要做,否则不会显示.

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn3.setCompoundDrawables(null, null,

drawable, null);

} else {

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn3.setCompoundDrawables(null, null,

drawable, null);

mShoplist_threelist.setVisibility(View.GONE);

threelistview = false;

}

if (mID == R.id.Shoplist_title_textbtn2) {

Drawable drawable = null;

if (!mainlistview2) {

drawable = getResources().getDrawable(

R.drawable.ic_arrow_up_black);

mShoplist_mainlist2.setVisibility(View.VISIBLE);

twoadapter2.notifyDataSetChanged();

mainlistview2 = true;

} else {

drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

mShoplist_mainlist2.setVisibility(View.GONE);

mainlistview2 = false;

}

// 这一步必须要做,否则不会显示.

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn2.setCompoundDrawables(null, null,

drawable, null);

} else {

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn2.setCompoundDrawables(null, null,

drawable, null);

mShoplist_mainlist2.setVisibility(View.GONE);

mainlistview2 = false;

}

if (mID == R.id.Shoplist_title_textbtn1) {

Drawable drawable = null;

if (!mainlistview1) {

drawable = getResources().getDrawable(

R.drawable.ic_arrow_up_black);

mShoplist_mainlist1.setVisibility(View.VISIBLE);

twoadapter1.notifyDataSetChanged();

mainlistview1 = true;

} else {

drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

mShoplist_mainlist1.setVisibility(View.GONE);

mainlistview1 = false;

}

// 这一步必须要做,否则不会显示.

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn1.setCompoundDrawables(null, null,

drawable, null);

} else {

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn1.setCompoundDrawables(null, null,

drawable, null);

mShoplist_mainlist1.setVisibility(View.GONE);

mainlistview1 = false;

}

}

}

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK) {

if (threelistview == true) {

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn3.setCompoundDrawables(null, null,

drawable, null);

mShoplist_threelist.setVisibility(View.GONE);

threelistview = false;

} else if (mainlistview1 == true) {

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn1.setCompoundDrawables(null, null,

drawable, null);

mShoplist_mainlist1.setVisibility(View.GONE);

mainlistview1 = false;

} else if (mainlistview2 == true) {

Drawable drawable = getResources().getDrawable(

R.drawable.ic_arrow_down_black);

drawable.setBounds(0, 0, drawable.getMinimumWidth(),

drawable.getMinimumHeight());

mShoplist_title_textbtn2.setCompoundDrawables(null, null,

drawable, null);

mShoplist_mainlist2.setVisibility(View.GONE);

mainlistview2 = false;

} else {

finish();

}

}

return false;

}

}

xml布局文件为:

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

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

android:layout_width="match_parent"

android:layout_height="match_parent" >

<RelativeLayout

android:id="@+id/titlerelativelayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/title_background"

android:gravity="center_vertical" >

<ImageView

android:id="@+id/Shoplist_back"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:paddingLeft="10dp"

android:src="@drawable/ic_back_u" />

<LinearLayout

android:id="@+id/Shoplist_shanghuleixing"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:gravity="center_vertical"

android:orientation="horizontal"

android:padding="10dp" >

<TextView

android:id="@+id/Shoplist_title_txt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:gravity="center_vertical"

android:text="全部商户"

android:textColor="#FF8C00"

android:textSize="18sp" />

<ImageView

android:id="@+id/Search_city_img"

android:layout_width="22dp"

android:layout_height="22dp"

android:src="@drawable/title_arrow_down_normal" />

</LinearLayout>

</RelativeLayout>

<LinearLayout

android:id="@+id/middlelinearlayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/titlerelativelayout" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tuan_tab_linear_background"

android:paddingBottom="0.5dp"

android:paddingLeft="0dp"

android:paddingRight="0.5dp"

android:paddingTop="0dp" >

<TextView

android:id="@+id/Shoplist_title_textbtn1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/my_tab_background"

android:drawableRight="@drawable/ic_arrow_down_black"

android:gravity="center_horizontal"

android:padding="10dp"

android:singleLine="true"

android:text="全部地区"

android:textColor="#666666" />

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tuan_tab_linear_background"

android:paddingBottom="0.5dp"

android:paddingLeft="0dp"

android:paddingRight="0.5dp"

android:paddingTop="0dp" >

<TextView

android:id="@+id/Shoplist_title_textbtn2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/my_tab_background"

android:drawableRight="@drawable/ic_arrow_down_black"

android:gravity="center_horizontal"

android:padding="10dp"

android:singleLine="true"

android:text="美食"

android:textColor="#666666" />

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tuan_tab_linear_background"

android:paddingBottom="0.5dp"

android:paddingLeft="0dp"

android:paddingRight="0.5dp"

android:paddingTop="0dp" >

<TextView

android:id="@+id/Shoplist_title_textbtn3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/my_tab_background"

android:drawableRight="@drawable/ic_arrow_down_black"

android:gravity="center_horizontal"

android:padding="10dp"

android:singleLine="true"

android:text="默认排序"

android:textColor="#666666" />

</LinearLayout>

</LinearLayout>

<ListView

android:id="@+id/ShopListView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_below="@+id/middlelinearlayout" />

<ListView

android:id="@+id/Shoplist_threelist"

android:layout_width="match_parent"

android:layout_height="350dp"

android:layout_below="@+id/middlelinearlayout"

android:background="#ffffff"

android:divider="@null"

android:listSelector="@android:color/transparent"

android:padding="3dp"

android:visibility="gone" />

<LinearLayout

android:id="@+id/Shoplist_mainlist2"

android:layout_width="match_parent"

android:layout_height="350dp"

android:layout_below="@+id/middlelinearlayout"

android:orientation="horizontal"

android:visibility="gone" >

<ListView

android:id="@+id/Shoplist_onelist2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="20"

android:background="#F4F4F4"

android:divider="@null"

android:listSelector="@android:color/transparent"

android:scrollbars="none" />

<ListView

android:id="@+id/Shoplist_twolist2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="17"

android:background="#FFFFFF"

android:divider="@null"

android:listSelector="@android:color/transparent" />

</LinearLayout>

<LinearLayout

android:id="@+id/Shoplist_mainlist1"

android:layout_width="match_parent"

android:layout_height="350dp"

android:layout_below="@+id/middlelinearlayout"

android:orientation="horizontal"

android:visibility="gone" >

<ListView

android:id="@+id/Shoplist_onelist1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="20"

android:background="#F4F4F4"

android:divider="@null"

android:listSelector="@android:color/transparent"

android:scrollbars="none" />

<ListView

android:id="@+id/Shoplist_twolist1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="17"

android:background="#FFFFFF"

android:divider="@null"

android:listSelector="@android:color/transparent" />

</LinearLayout>

</RelativeLayout>

public class Model {

public static int[] LISTVIEWIMG = new int[] {

R.drawable.ic_category_2147483648, R.drawable.ic_category_10,

R.drawable.ic_category_20, R.drawable.ic_category_30,

R.drawable.ic_category_45, R.drawable.ic_category_50,

R.drawable.ic_category_55, R.drawable.ic_category_60,

R.drawable.ic_category_65, R.drawable.ic_category_70,

R.drawable.ic_category_80, R.drawable.ic_category_none };

// 第一个listview的文本数据数组

public static String[] LISTVIEWTXT = new String[] { "热门分类", "美食", "购物",

"休闲娱乐", "运动健身", "丽人", "结婚", "酒店", "爱车", "亲子", "生活服务", "家装" };

// 第二个listview的文本数据

public static String[][] MORELISTTXT = {

{ "全部分类", "小吃快餐", "咖啡厅", "电影院", "KTV", "茶馆", "足疗按摩", "超市/便利店",

"银行", "经济型酒店", "景点/郊游", "公园", "美发" },

{ "全部美食", "小吃快餐", "西餐", "火锅", "北京菜", "川菜", "日本", "面包甜点", "粤菜",

"韩国料理", "自助餐", "浙江菜", "云南菜", "湘菜", "东南亚菜", "西北菜", "鲁菜",

"东北菜", "素菜", "新疆菜", "海鲜", "清真菜", "贵州菜", "湖北菜", "其他" },

{ "全部购物", "综合商场", "服饰鞋包", "超市", "特色集市", "品牌折扣店", "眼镜店", "珠宝饰品",

"化妆品", "运动户外", "食品茶酒", "书店", "数码产品", "药店", "京味儿购物", "亲子购物",

"花店", "家具建材", "更多购物场所" },

{ "全部休闲娱乐", "咖啡厅", "KTV", "景点/郊游", "电影院", "酒吧", "公园", "温泉", "文化艺术",

"足疗按摩", "洗浴", "茶馆", "游乐游艺", "密室", "农家乐", "桌面游戏", "台球馆",

"DIY手工坊", "休闲网吧", "真人CS", "棋牌室", "轰趴馆", "私人影院", "更多休闲娱乐" },

{ "全部运动健身", "健身中心", "游泳馆", "瑜伽", "羽毛球馆", "台球馆", "舞蹈", "体育场馆",

"高尔夫场", "网球场", "武术场馆", "篮球场", "保龄球馆", "足球场", "乒乓球馆",

"更多体育运动" },

{ "全部丽人", "美发", "美容/SPA", "齿科", "美甲", "化妆品", "瑜伽", "瘦身纤体", "舞蹈",

"个性写真", "整形" },

{ "全部结婚", "婚纱摄影", "婚宴酒店", "婚纱礼服", "婚庆公司", "婚戒首饰", "个性写真", "彩妆造型",

"婚礼小礼品", "婚礼跟拍", "婚车租赁", "司仪主持", "婚房装修", "更多婚礼服务" },

{ "全部酒店", "经济型酒店", "五星级酒店", "度假村", "四星级酒店", "三星级酒店", "农家院",

"公寓式酒店", "青年旅社", "精品酒店", "更多酒店住宿" },

{ "全部爱车", "维修保养", "驾校", "停车场", "4S店/汽车销售", "加油站", "配件/车饰", "汽车租赁",

"汽车保险" },

{ "全部亲子", "亲子摄影", "幼儿教育", "亲子游乐", "孕产护理", "亲子购物", "更多亲子服务" },

{ "全部生活服务", "医院", "银行", "齿科", "宠物", "培训", "快照/冲印", "学校", "旅行社",

"购物网站", "干洗店", "家政", "奢侈品护理", "商务楼", "小区", "更多生活服务" },

{ "全部家装", "家具家装", "家用电器", "建材", "家装卖场", "装修设计" } };

// shoplist中排序文本

// public static String[] SHOPLIST_THREELIST = { "默认排序", "距离最近", "人气最高",

// "评价最好", "口味最佳", "环境最雅", "服务最好", "费用最低", "费用最高" };

public static String[] SHOPLIST_THREELIST = { "默认排序", "距离最近", "人气最高",

"评价最好", "服务最好" };

// shoplist中商区文本

public static String[] SHOPLIST_PLACE = new String[] { "附近", "全城热门商区",

"道里区", "道外区", "南岗区", "香坊区", "平房区", "松北区", "呼兰区", "近郊" };

// 美食全部地区数组2

public static String[][] SHOPLIST_PLACESTREET = new String[][] {

{ "500米", "1000米", "2000米", "5000米" },

{ "全部商区", "中央大街", "开发区", "秋林", "哈工大", "菜艺街", "爱建社区", "芦家街/宣化街",

"新阳路", "学府路", "三大动力路", "革新街", "江畔景区", "南极区", "和兴路沿线",

"哈尔滨东站", "群力地区", "军工院", "阿城区", },

{ "全部道里区", "中央大街", "爱建社区", "新阳路", "群力地区", "顾乡" },

{ "全部道外区", "江畔景区", "南极街", "哈尔滨东站", "太平桥", "靖宇街沿线", "宏伟路" },

{ "全部南岗区", "开发区", "秋林", "哈工大", "芦家街/宣化街", "学府路", "革新街", "和兴路沿线",

"军工院", "哈尔滨站", "哈西大街", },

{ "全部香坊区", "菜艺街", "三大动力路", "民生路", "木材街", "安埠街", },

{ "全部平房区", "新疆大街", },

{ "全部松北区", "太阳岛", "世茂大道", "中源大道", },

{ "全部呼兰区", "学院路", },

{ "全部近郊", "阿城区", "尚志市", "五常市", "宾县", "方正县", "延寿县", "双城市", "通河县",

"巴彦县", "木兰县", "依兰县", } };

}

public class SearchMainAdapter extends BaseAdapter {

private Context ctx;

private List<Map<String, Object>> list;

private int position = 0;

private boolean islodingimg = true;

private int layout = R.layout.search_more_mainlist_item;

public SearchMainAdapter(Context ctx, List<Map<String, Object>> list) {

this.ctx = ctx;

this.list = list;

}

public SearchMainAdapter(Context ctx, List<Map<String, Object>> list,

int layout, boolean islodingimg) {

this.ctx = ctx;

this.list = list;

this.layout = layout;

this.islodingimg = islodingimg;

}

public int getCount() {

return list.size();

}

public Object getItem(int arg0) {

return list.get(arg0);

}

public long getItemId(int arg0) {

return arg0;

}

public View getView(int arg0, View arg1, ViewGroup arg2) {

Holder hold;

if (arg1 == null) {

hold = new Holder();

arg1 = View.inflate(ctx, layout, null);

hold.txt = (TextView) arg1

.findViewById(R.id.Search_more_mainitem_txt);

hold.img = (ImageView) arg1

.findViewById(R.id.Search_more_mainitem_img);

hold.layout = (LinearLayout) arg1

.findViewById(R.id.Search_more_mainitem_layout);

arg1.setTag(hold);

} else {

hold = (Holder) arg1.getTag();

}

if(islodingimg == true){

hold.img.setImageResource(Integer.parseInt(list.get(arg0).get("img")

.toString()));

}

hold.txt.setText(list.get(arg0).get("txt").toString());

hold.layout

.setBackgroundResource(R.drawable.search_more_mainlistselect);

if (arg0 == position) {

hold.layout.setBackgroundResource(R.drawable.list_bkg_line_u);

}

return arg1;

}

public void setSelectItem(int i) {

position = i;

}

public int getSelectItem() {

return position;

}

private static class Holder {

LinearLayout layout;

ImageView img;

TextView txt;

}

}

public class SearchMoreAdapter extends BaseAdapter {

private Context ctx;

private String[] text;

private int position = 0;

private int layout = R.layout.search_more_morelist_item;

public SearchMoreAdapter(Context ctx, String[] text) {

this.ctx = ctx;

this.text = text;

}

public SearchMoreAdapter(Context ctx, String[] text, int layout) {

this.ctx = ctx;

this.text = text;

this.layout = layout;

}

public int getCount() {

return text.length;

}

public Object getItem(int arg0) {

return text[arg0];

}

public long getItemId(int arg0) {

return arg0;

}

public View getView(int arg0, View arg1, ViewGroup arg2) {

Holder hold;

if (arg1 == null) {

hold = new Holder();

arg1 = View.inflate(ctx, layout, null);

hold.txt = (TextView) arg1

.findViewById(R.id.Search_more_moreitem_txt);

hold.layout = (LinearLayout) arg1

.findViewById(R.id.More_list_lishi);

arg1.setTag(hold);

} else {

hold = (Holder) arg1.getTag();

}

hold.txt.setText(text[arg0]);

hold.layout.setBackgroundResource(R.drawable.my_list_txt_background);

hold.txt.setTextColor(Color.parseColor("#FF666666"));

if (arg0 == position) {

hold.layout

.setBackgroundResource(R.drawable.search_more_morelisttop_bkg);

hold.txt.setTextColor(Color.parseColor("#FFFF8C00"));

}

return arg1;

}

public void setSelectItem(int i) {

position = i;

}

private static class Holder {

LinearLayout layout;

TextView txt;

}

}

布局文件shop_list1_item:

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:padding="0dp" >

<LinearLayout

android:id="@+id/Search_more_mainitem_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/search_more_mainlistselect"

android:gravity="center_vertical"

android:orientation="horizontal"

android:padding="0dp" >

<ImageView

android:id="@+id/Search_more_mainitem_img"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingBottom="11dp"

android:paddingLeft="10dp"

android:paddingTop="11dp" />

<!-- android:src="@drawable/ic_category_2147483648" -->

<TextView

android:id="@+id/Search_more_mainitem_txt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="10dp"

android:paddingBottom="9dp"

android:paddingTop="9dp"

android:text="热门分类"

android:textColor="#000000"

android:textSize="18sp" />

</LinearLayout>

</LinearLayout>

布局文件shop_list2_item:

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/my_tab_background"

android:orientation="vertical"

android:paddingBottom="0dp"

android:paddingLeft="10dp" >

<LinearLayout

android:id="@+id/More_list_lishi"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/my_list_txt_background"

android:gravity="center_vertical"

android:paddingBottom="0dp" >

<TextView

android:id="@+id/Search_more_moreitem_txt"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center_vertical"

android:paddingBottom="8.5dp"

android:paddingTop="8dp"

android:text="全部分类"

android:textColor="#666666"

android:textSize="17sp" />

</LinearLayout>

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息