freedom_wings 2015-11-17 12:46 采纳率: 21.1%
浏览 1659
已采纳

安卓,新建simpleAdapter报错,求大神看看

在girdview中添加simpleAdapter,为什么新建SimpleAdapter的时候会报错?

我的代码如下:

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">

<GridView
    android:id="@+id/gridview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>






</LinearLayout>

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".activity"
android:orientation="vertical">

<ImageView 
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

</LinearLayout>

package com.example.test4;

import android.os.Bundle;
import android.widget.*;
import java.util.*;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

SimpleAdapter s=null;
GridView grid=null;
List<Map<String,Integer>> list=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    grid=(GridView)super.findViewById(R.id.gridview);
    initAdapter();
    grid.setAdapter(s);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public void initAdapter()
{
    Map<String,Integer> map=new HashMap<String,Integer>();
    map.put("图片", R.drawable.a1);
    list.add(map);
    map.put("图片", R.drawable.a2);
    list.add(map);
    map.put("图片", R.drawable.a1);
    list.add(map);
    s=new SimpleAdapter(MainActivity.this,list,R.layout.imageview,new String[]{"图片"},new Integer[]{R.id.image});




}

}

其中,s=new SimpleAdapter.....那行被报错,我截张图:
图片说明

应该就是说构造方法没这样的重载,明明就应该没错的吧,请问这里是怎么回事?应该怎么解决?

  • 写回答

4条回答 默认 最新

  • JPF1024 2015-11-18 01:46
    关注

    你这样添加有问题,而且你最后那个不能用new Integer[]{},应该用new int[]{}.这样的。

    你那个添加有问题。

    像下面这样添加,然后把你SimpleAdapter初始化的“图片”改成"image"

     Map<String,Integer> maps1 = new HashMap<String,Integer>();
    maps1.put("image",R.drawable.a1);
    Map<String,Integer> maps2 = new HashMap<String,Integer>();
    maps2.put("image",R.drawable.a2);
    Map<String,Integer> maps3 = new HashMap<String,Integer>();
    maps3.put("image",R.drawable.a3);
    list.add(maps1);
    list.add(maps2);
    list.add(maps3);
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配