Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 简单列表项目模式下的空ListView ArrayList成员列表=新建ArrayList(); HashMap项=新建HashMap(); 项目出售(“asdf”、“asdf”); 成员列表。添加(项目); 项目。出售(“ffff”、“ffff”); 成员列表。添加(项目); SimpleAdapter SimpleAdapter=new SimpleAdapter(MainActivity.this,MemberList,android.R.layout.simple_list_item_2,新字符串[]{“Name”,“Level”}, 新的int[]{android.R.id.text1,android.R.id.text2}); list.setAdapter(simpledapter);_Java_Android_Android Listview - Fatal编程技术网

Java 简单列表项目模式下的空ListView ArrayList成员列表=新建ArrayList(); HashMap项=新建HashMap(); 项目出售(“asdf”、“asdf”); 成员列表。添加(项目); 项目。出售(“ffff”、“ffff”); 成员列表。添加(项目); SimpleAdapter SimpleAdapter=new SimpleAdapter(MainActivity.this,MemberList,android.R.layout.simple_list_item_2,新字符串[]{“Name”,“Level”}, 新的int[]{android.R.id.text1,android.R.id.text2}); list.setAdapter(simpledapter);

Java 简单列表项目模式下的空ListView ArrayList成员列表=新建ArrayList(); HashMap项=新建HashMap(); 项目出售(“asdf”、“asdf”); 成员列表。添加(项目); 项目。出售(“ffff”、“ffff”); 成员列表。添加(项目); SimpleAdapter SimpleAdapter=new SimpleAdapter(MainActivity.this,MemberList,android.R.layout.simple_list_item_2,新字符串[]{“Name”,“Level”}, 新的int[]{android.R.id.text1,android.R.id.text2}); list.setAdapter(simpledapter);,java,android,android-listview,Java,Android,Android Listview,这是我的java代码 但是。。。。 只有两个空格 ListView中没有文本 我该怎么办?换成 ArrayList<HashMap<String, String>> MemberList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> item = new HashMap<String, String>(); item.put("asd

这是我的java代码

但是。。。。 只有两个空格

ListView中没有文本

我该怎么办?

换成

ArrayList<HashMap<String, String>> MemberList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> item = new HashMap<String, String>();

item.put("asdf", "asdf");
MemberList.add(item);
item.put("ffff", "ffff");
MemberList.add(item);
SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, MemberList, android.R.layout.simple_list_item_2, new String[] { "Name", "Level" },
        new int[] { android.R.id.text1, android.R.id.text2 });

list.setAdapter(simpleAdapter);
你有

  SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, MemberList, android.R.layout.simple_list_item_2, new String[] { "asdf", "ffff" },
    new int[] { android.R.id.text1, android.R.id.text2 });
所以你需要

 item.put("asdf", "asdf");
 item.put("ffff", "ffff"); 
看看构造器

 new String[] { "asdf", "ffff" }, 
publicsimpledapter(上下文,列表>数据,int资源,字符串[]from,int[]to)
在API级别1中添加
建造师
参数
上下文与此SimpleAdapter关联的视图正在运行的上下文
地图列表中的数据。列表中的每个条目对应于列表中的一行。映射包含每行的数据,并且应该包括“from”中指定的所有条目
定义此列表项视图的视图布局的资源标识符。布局文件应至少包括“到”中定义的命名视图
从将添加到与每个项目关联的映射的列名列表中。
到“from”参数中应显示列的视图。这些都应该是文本视图。此列表中的前N个视图提供了from参数中前N列的值。
以下是解决方案:

public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

Added in API level 1
Constructor

Parameters
context The context where the View associated with this SimpleAdapter is running
data    A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from"
resource    Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to"
from    A list of column names that will be added to the Map associated with each item.
to  The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.
ListView list=(ListView)findviewbyd(R.id.list);
ArrayList arr_adt=新的ArrayList();
HashMap项=新建HashMap();
ArrayList MemberList=新的ArrayList();
项目出售(“asdf”、“asdf”);
成员列表。添加(项目);
项目。出售(“ffff”、“ffff”);
成员列表。添加(项目);
Toast.makeText(getApplicationContext(),MemberList.toString(),
Toast.LENGTH_LONG).show();
Log.i(“MAP”,MemberList.toString());
SimpleAdapter SimpleAdapter=新SimpleAdapter(MainActivity.this,
成员列表,android.R.layout.simple\u list\u item\u 2,
新字符串[]{“asdf”,“ffff”},新int[]{android.R.id.text1,android.R.id.text2});
list.setAdapter(simpledapter);

希望这有帮助。:)

将数据添加到ArrayList中。。如果您记录它,您将看到其中的值。您需要为每个项目创建新映射
ListView list = (ListView) findViewById(R.id.list);

ArrayList<String> arr_adt = new ArrayList<String>();

HashMap<String, String> item = new HashMap<String, String>();
ArrayList<HashMap<String, String>> MemberList = new ArrayList<HashMap<String, String>>();

item.put("asdf", "asdf");
MemberList.add(item);
item.put("ffff", "ffff");
MemberList.add(item);

Toast.makeText(getApplicationContext(), MemberList.toString(),
        Toast.LENGTH_LONG).show();
Log.i("MAP", MemberList.toString());

SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this,
        MemberList, android.R.layout.simple_list_item_2,
        new String[] {"asdf","ffff"}, new int[] {android.R.id.text1,android.R.id.text2});

list.setAdapter(simpleAdapter);