循环以填充String数组以在listview中使用(不从循环填充)

时间:2015-11-05 21:29:38

标签: java android

如何使用" CurrlstArr"无法显示价值。我不知道使用for循环字符串数组的问题是什么。

    mainListView = (ListView) findViewById( R.id.listView100 );


     SharedPreferences prefs = getSharedPreferences("MY_FAVOURITES", MODE_PRIVATE); 
String    test_string = prefs.getString("name", "");

  persons = test_string.split("DDDDDDDDDD");

 int  t = persons.length;

  if(t<0)

  {
      Toast.makeText(getApplicationContext(),"xtronlabs", Toast.LENGTH_SHORT).show();
  }
  else

  {
      for (int i = 0; i < persons.length; i++)
      {
      String currlst = persons[i];
    currlstArr = currlst.split("LLLLLLLLLL");  

    caption = currlstArr[0];

     vlink = currlstArr[1];


      }


    mainListView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,currlstArr ));

  }

如何在listview上使用字符串值我不知道我的错误。

1 个答案:

答案 0 :(得分:1)

您缺少声明“currlstArr”的部分。您正在foreach中设置currlstArr的值,因此,如果t&lt; 0你没有设置,否则,你有.split的值。您对setAdapter本身的使用看起来很好。尝试

currlstArr = new String[] { "Android", "iPhone", "WindowsMobile",
        "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
        "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux",
        "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
        "Android", "iPhone", "WindowsMobile" };