package a6.situo.com.a6;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.SimpleAdapter;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Objects;public class MainActivity extends AppCompatActivity { private ListView listView; private ArrayAdapter arrayAdapter; private SimpleAdapter simp_adapter; private List<Map<String,Objects>>dataList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView= (ListView) findViewById(R.id.list_item); String[] i={"商品一","商品二","商品三","商品四","商品五","商品六",}; dataList = new ArrayList<Map<String, Objects>>(); arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,i); simp_adapter = new SimpleAdapter(this,getData(), R.layout.item, new String[]{"pic","text01"},new int[]{R.id.pic,R.id.text01}); listView.setAdapter(simp_adapter); } private List<Map<String,Objects>> getData(){ for(int j = 0;j<20;j++) { Map<String,Objects> map=new HashMap<String,Objects>(); map.put("pic",R.drawable.one_0); map.put("text01","商品"+j); dataList.add(map); } return dataList; }}
目前暂无任何回答
- 0 回答
- 0 关注
- 962 浏览
添加回答
举报
0/150
提交
取消