1. 程式人生 > >多級下拉列表選擇處理

多級下拉列表選擇處理

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>