Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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
Android 如何添加listview数据_Android_Listview - Fatal编程技术网

Android 如何添加listview数据

Android 如何添加listview数据,android,listview,Android,Listview,我想向listview添加数据,但我的数据是字符串[],arraylist是Planet[] 当我的代码是这样时,我只添加一项 String[] zapasyList3 = ligy.split("<br/>"); for (int i=0; i<5; i++){ planets = new Planet[] { new Planet (zapasyList3[i]) }; } ArrayList<Plane

我想向listview添加数据,但我的数据是字符串[],arraylist是Planet[] 当我的代码是这样时,我只添加一项

String[] zapasyList3 = ligy.split("<br/>");

for (int i=0; i<5; i++){ 
planets = new Planet[] {  new Planet (zapasyList3[i])
          };  
        }

        ArrayList<Planet> planetList = new ArrayList<Planet>();
        planetList.addAll( Arrays.asList(planets) );

        // Set our custom array adapter as the ListView's adapter.
        listAdapter = new PlanetArrayAdapter(getBaseContext (), planetList);

        mainListView.setAdapter( listAdapter );      
        listAdapter.notifyDataSetChanged();
谢谢

那么:

planets = new Planet[5];
for (int i=0; i<5; i++){ 
    planets[i] = new Planet (zapasyList3[i]);
}  
//.. add the planets array now

您也可以将行星声明为ArrayList或regular array。。由您决定。

发布行星类的代码。