1,创建XML文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > //下拉选择框 <Spinner android:id="@+id/idspinnerone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" /> <Spinner android:id="@+id/idspinnertwo" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <Spinner android:id="@+id/idspinnerthw" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <Spinner android:id="@+id/idspinnerfin" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"/> </LinearLayout> <ListView android:layout_marginTop="10dp" android:id="@+id/idlistview" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/imgeviewmeituan" android:layout_width="100dp" android:layout_height="100dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dp" > //列表主题 <TextView android:id="@+id/simpletextonemeituan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/holo_red_light" android:textSize="16dp" /> //列表内容 <TextView android:id="@+id/simpletexttwomeituan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="14sp" /> </LinearLayout> </LinearLayout> </LinearLayout>
--------------------------------------------------------------------------------------------------------------------------------------------------------
2、创建一个java文件
package com.example.demoones; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Spinner; import java.util.ArrayList; import java.util.List; /** * Created by Administrator on 14-11-26. */ public class Activty_meituan extends Activity { private ListView alistview; //数据源 private Spinner spinnersxone, spinnersxtwo, spinnerthw, spinnerfin; String[] array = {"成华区", "锦江区", "武侯区", "青羊区", "金牛区"}; String[] array1 = {"火锅", "西餐", "中餐", "烧烤", "自助"}; String[] array2 = {"离我最近", "评价", "中餐", "烧烤", "自助"}; String[] array3 = {"筛选", "电影/在线选座", "酒店", "娱乐", "spas"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.meituanlistview_layout); alistview = (ListView) findViewById(R.id.idlistview); //初始化spinner的id spinnersxone = (Spinner) findViewById(R.id.idspinnerone); spinnersxtwo = (Spinner) findViewById(R.id.idspinnertwo); spinnerthw = (Spinner) findViewById(R.id.idspinnerthw); spinnerfin = (Spinner) findViewById(R.id.idspinnerfin); //绑定适配器数据源 MyBaseAdapter adapter0 = new MyBaseAdapter(this, getData()); ArrayAdapter adapter = new ArrayAdapter(this, R.layout.spinnertextview, array); ArrayAdapter adapter1 = new ArrayAdapter(this, R.layout.spinnertextview, array1); ArrayAdapter adapter2 = new ArrayAdapter(this, R.layout.spinnertextview, array2); ArrayAdapter adapter3 = new ArrayAdapter(this, R.layout.spinnertextview, array3); spinnersxone.setAdapter(adapter); spinnersxtwo.setAdapter(adapter1); spinnerthw.setAdapter(adapter2); spinnerfin.setAdapter(adapter3); alistview.setAdapter(adapter0); } //定义数据源 public ArrayList getData() { ArrayList list = new ArrayList(); Massagess msg = new Massagess(); msg.setId(10); msg.setTitle("【3店通yong金汉斯乐享自助"); msg.setHeaderIcon(R.drawable.han); msg.setContent("无需预约,消费高峰时可能需要等位\n" + " 温馨提示\n" + " 每张美团券最多1位成人使用\n" + " 儿童、老人、学生等优惠详询门店\n" + " 金汉斯不同门店的菜品会有不同,请以店内当日实际供应为准\n" + " 团购用户不可同时享受商家其他优惠\n" + " 部分菜品因时令原因有所不同,请以店内当日实际供应为准" + " ----分数(4.7)"); msg = new Massagess(); msg.setId(10); msg.setTitle("【3店通用】巴萨奴纳"); msg.setHeaderIcon(R.drawable.ba); msg.setContent("仅售51元!价值68元的单人自助晚餐,提供免费WiFi。" + "让您品尝精致牛排美味,享受时尚优雅环境。巴萨奴纳欢享牛排自助,(江北大融城店)盛大开业。" + " ----分数(4.7)"); list.add(msg); msg = new Massagess(); msg.setId(10); msg.setTitle("【春熙路】Chuncoffee淳咖啡"); msg.setHeaderIcon(R.drawable.han); msg.setContent("仅售1元!价值20元的原味松饼(半份体验装)1份," + "提供免费WiFi。感恩节新品,体验时间仅为27日至30日,请注意分配时间" + " ----分数(4.7)"); list.add(msg); msg = new Massagess(); msg.setId(10); msg.setTitle("【春熙路】星际里美食汇·海鲜自助\n"); msg.setHeaderIcon(R.drawable.haix); msg.setContent("仅售58元!价值148元的单人自助午餐预售,提供免费WiFi。12月18日开业前大酬宾,限时抢购,欲购从速。" + " ----分数(4.7)"); list.add(msg); msg = new Massagess(); msg.setId(10); msg.setTitle("【春熙路】星际里美食汇·海鲜自助\n"); msg.setHeaderIcon(R.drawable.shu); msg.setContent("仅售58元!价值148元的单人自助午餐预售,提供免费WiFi。" + " ----分数(4.7)"); //添加 list.add(msg); return list; } }
---------------------------------------------------------------------------------------------------------------------------------------------------
定义适配器
package com.example.demoones; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; /** * Created by Administrator on 14-11-26. */ public class MyBaseAdapter extends BaseAdapter { private List mList = new ArrayList(); private LayoutInflater mInflater; private Context mcontext; // public MyBaseAdapter(Context context) { // mcontext = context; // mInflater = LayoutInflater.from(mcontext); // } public MyBaseAdapter(Context context, ArrayList list) { mcontext = context; mInflater = LayoutInflater.from(mcontext); mList = list; } // public void setData(ArrayListList list) { // mList = list; // } @Override public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; Massagess msg; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.meituanlistview_layout, null); holder.iconImg = (ImageView) convertView.findViewById(R.id.imgeviewmeituan); holder.titleTxt = (TextView) convertView.findViewById(R.id.simpletextonemeituan); holder.infoTxt = (TextView) convertView.findViewById(R.id.simpletexttwomeituan); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // Massagess msg = new Massagess(); msg=(Massagess)mList.get(position); holder.iconImg.setImageResource(msg.getHeaderIcon()); holder.titleTxt.setText(msg.getTitle()); holder.infoTxt.setText(msg.getContent()); return convertView; } class ViewHolder { ImageView iconImg = null; TextView titleTxt = null; TextView infoTxt = null; } }
------------------------------------------------------------------------------------------------------------------------------------------------------
定义属性
package com.example.demoones; /** * Created by Administrator on 14-11-26. */ public class Massagess { private int id; private String title; private String content; private int headerIcon; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public int getHeaderIcon() { return headerIcon; } public void setHeaderIcon(int headerIcon) { this.headerIcon = headerIcon; } }