下面map.put("pic",R.drawable.one_0); map.put("text01","商品"+j);显示int不能转换为Objects

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;
   }
}

慕粉1629534212
浏览 963回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android