项目需求,需要在项目里加入点餐的功能,自己简单写了一个,
先看图,界面丑勿喷:
只是做了简单的效果,实现点击左边右边改变,滑动右边左边改变,代码量很少,可以参考下
这是项目目录:
布局文件
左边listView 适配器
public class LeftAdapter extends BaseAdapter{
private List<LeftMenu> dataList;
private Context contex;
private LayoutInflater inflater;
private int currentItem = 0;//当前item
private String click;
public LeftAdapter(Context context,List<LeftMenu> datas,int pos,String isClick) {
// TODO Auto-generated constructor stub
this.click = isClick;
= context;
this.dataList = datas;
this.currentItem = pos;
this.inflater = LayoutInflater.from(context);
}
public LeftAdapter(Context context,List<LeftMenu> datas) {
// TODO Auto-generated constructor stub
= context;
this.dataList = datas;
this.inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return dataList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView == null){
convertView = inflater.inflate(R.layout.left_item, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}else {
holder = (ViewHolder) Tag();
}
LeftMenu menu = (position);
View.LeftMenu());
if(click != ""){//如果点击不为空,就是点击了左边的item
if(currentItem == position){//如果当前条目等于position
View.setBackgroundColor(Color.BLUE);//设置选择状态的背景颜色
}
}else {
if(position == 0){
View.setBackgroundColor(Color.BLUE);//设置未选择状态的背景颜色
}
}
return convertView;
}
class ViewHolder{
TextView textView;
public ViewHolder(View convertView) {
// TODO Auto-generated constructor stub
textView = (TextView) convertView.findViewById(R.id.left_lv);
}
}
}
右边适配器
public class RightAdapter extends BaseAdapter{
private List<RightMenu> dataList;
private Context contex;
private LayoutInflater inflater;
private RightItemAdapter itemAdapter;
public RightAdapter(Context context,List<RightMenu> data) {
// TODO Auto-generated constructor stub
this.dataList =data;
= context;
this.inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return dataList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView == null){
convertView = inflater.inflate(R.layout.right_item, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}else {
holder = (ViewHolder) Tag();
}
itemAdapter = new RightItemAdapter(contex,dataList,position);
holder.cListView.setAdapter(itemAdapter);
RightMenu menu = (position);
View.RightTitle());
return convertView;
}
class ViewHolder{
CostomListView cListView;
TextView textView;
public ViewHolder(View convertView) {
// TODO Auto-generated constructor stub
textView = (TextView) convertView.findViewById(R.id.right_lv);
cListView = (CostomListView) convertView.findViewById(R.id.right_cos_list);
}
}
}
下载地址
本文发布于:2024-02-01 01:31:16,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170672227832867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |