12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | package import import
import
import
import
import import public MyActivity extends
private
private
private
public ImageAdapterView imageAdapterView; private
private
R.drawable.niao,R.drawable.niao,R.drawable.rui,R.drawable.rui, R.drawable.ning,R.drawable.ning }; private
"土豆丝" , "土豆块" , "土豆泥" , "红烧土豆" , "麻辣土豆" , "清蒸土豆" }; private
"土豆丝:便宜又好吃" , "土豆丝:便宜又好吃" , "土豆丝:便宜又好吃" , "土豆丝:便宜又好吃" , "土豆丝:便宜又好吃" , "土豆丝:便宜又好吃" , }; private
[] money={ 2 , 3 , 3 , 10 , 8 , 13 }; public onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); /**全屏显示**/ requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); gridView=(GridView) this .findViewById(R.id.gridView1); imageAdapterView = new
this ); gridView.setAdapter(imageAdapterView); gallery = (Gallery) this .findViewById(R.id.gallery1); listItems = getListItems(); listViewAdapter = new
this ,listItems); gallery.setAdapter(listViewAdapter); } private
List<Map<String,Object>> listItems = new
for ( int
0 ;i<goodsNames.length;i++){ Map<String,Object> map = new
map.put( "image" , imgeIDs[i]); map.put( "title" , goodsNames[i]); map.put( "info" , money[i]+ "元" ); listItems.add(map); } return
} } |
4. [代码]Gallery
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 | package import
import
import
import
import
import import
import
import import public ImageAdapter extends
private
private
private
private
[] hasChecked; public class ListItemView{ public
public
public
public
} public
this .context = context; listContainer = LayoutInflater.from(context); this .listItems = listItems; hasChecked = new
[getCount()]; } @Override public getCount() { // TODO Auto-generated method stub return
} @Override public
int
// TODO Auto-generated method stub return
; } @Override public getItemId( int
// TODO Auto-generated method stub return
; } @Override public
int
final selectId = position; ListItemView listItemView = null ; if (convertView == null ){ listItemView = new
convertView = listContainer.inflate(R.layout.list_item, null ); //获得控件对象 listItemView.image =(ImageView) convertView.findViewById(R.id.imageitem); listItemView.title =(TextView) convertView.findViewById(R.id.textview); listItemView.info =(TextView) convertView.findViewById(R.id.textview1); listItemView.add =(Button) convertView.findViewById(R.id.button1); //设置空间集到convertView convertView.setTag(listItemView); } else { listItemView = (ListItemView) convertView.getTag(); } //设置文字图片 listItemView.image.setBackgroundResource((Integer)listItems.get(position).get( "image" )); listItemView.title.setText((String)listItems.get(position).get( "title" )); listItemView.info.setText((String) listItems.get(position).get( "info" )); listItemView.add.setOnClickListener( new
@Override public onClick(View v) { Map<String,Object> map = new
map.put( "image" , listItems.get(selectId).get( "image" )); ImageAdapterView.menuList.add(map); MyActivity.imageAdapterView.notifyDataSetChanged(); } }); return
} } |
5. [代码]GridView
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | package import
import
import
import
import
import
import
import import public ImageAdapterView extends
private
private
public List<Map<String,Object>> menuList = new
public class ItemListView{ public
} public
this .context = context; layoutInflater = LayoutInflater.from(context); } public getCount() { // TODO Auto-generated method stub return
} @Override public
int
// TODO Auto-generated method stub return
; } @Override public getItemId( int
// TODO Auto-generated method stub return
; } @Override public
int
ItemListView itemListView = null ; if (convertView== null ){ itemListView = new
convertView = layoutInflater.inflate(R.layout.item_list1, null ); itemListView.image=(ImageButton) convertView.findViewById(R.id.menuImage); convertView.setTag(itemListView); } else
itemListView=(ItemListView)convertView.getTag(); } itemListView.image.setBackgroundResource((Integer)menuList.get(position).get( "image" )); itemListView.image.setOnClickListener( new
@Override public onClick(View v) { // TODO Auto-generated method stub Toast.makeText(context, "触发成功" , Toast.LENGTH_SHORT).show(); } }); return
} } |