开发者社区> 问答> 正文

我在界面中用了一个ListView,Activity中一直报错?报错

  我把页面要显示的数据放在类DataSource_wifi里面了,下面是我的DataSource_wifi

public class DataSource_wifi {
 
 public DataSource_wifi(){
  
 }
 public List<Map<String, Object>> getData(){
  
  List<Map<String, Object>>list = new ArrayList<Map<String,Object>>();
  
  Map<String, Object> map = new HashMap<String, Object>();
  map.put("text_wifi", "neusoft");
  map.put("image_wifi", R.drawable.ic_launcher);
  list.add(map);
  
  map = new HashMap<String, Object>();
  map.put("text_wifi", "TP_LINK_MINI");
  map.put("image_wifi", R.drawable.ic_launcher);
  list.add(map);
  
  map = new HashMap<String, Object>();
  map.put("text_wifi", "cisco-2");
  map.put("image_wifi", R.drawable.ic_launcher);
  list.add(map);
  
  map = new HashMap<String, Object>();
  map.put("text_wifi", "TP-WiFi");
  map.put("image_wifi", R.drawable.ic_launcher);
  list.add(map);
  
  return list;
 }

下面是我的Activity

public class Wifi_Activity extends Activity{ 
 
 private TextView mTitleView;
 private ListView listView;
 private DataSource_wifi dataSource;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.wifi);
  prepareView();
  mTitleView.setText(R.string.wifi);   
  listView.setAdapter(new ArrayAdapter<String>(this,     android.R.layout.simple_expandable_list_item_1, dataSource.getData()));
 }
 
 private void prepareView() {
  mTitleView = (TextView) findViewById(R.id.title_text);
  listView = (ListView) findViewById(R.id.listview_wifi);
 }

listView.setAdapter(new ArrayAdapter<String>(this,     android.R.layout.simple_expandable_list_item_1, dataSource.getData()));处报错,说要把getData的类型变成int

我在用快捷键选在这个方法的时候已经选择的是list类型的了,不知道什么情况,希望会的帮忙看下,谢谢

 

展开
收起
爱吃鱼的程序员 2020-06-22 20:23:56 340 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    报错具体内容呢。。。listView.setAdapter(newArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,dataSource.getData()));

    <spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">setContentView(R.layout.wifi);

    <spanstyle="font-size:14px;line-height:22px;">放到后面,测试一下

    <spanstyle="background-color:#cce8cc;">一共两个错:1removeargumenttomatchArrayAdapter<String>(Context,int)

    <spanstyle="background-color:#cce8cc;">2,changereturntypeof getData()toint


    <spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">  prepareView();
    <spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">  mTitleView.setText(R.string.wifi);   

    <spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">  listView.setAdapter(newArrayAdapter<String>(this,    android.R.layout.simple_expandable_list_item_1,dataSource.getData()));

    <spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">setContentView(R.layout.wifi);

    这样不行

    listView.setAdapter(newArrayAdapter<Map<String,Object>>(this,android.R.layout.simple_expandable_list_item_1,dataSource.getData()));

    <spanstyle="background-color:#cce8cc;">这样写就没事了

    2020-06-22 20:24:15
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载