city0666
city0666

Reputation: 427

Loop to fill an String array for use in listview (not fill from loop)

How to use "CurrlstArr" is not able to show the value . I dont know whats the problem using for loop string array.

    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 ));

  }

How to use String value on listview i dnt know what my error.

Upvotes: 2

Views: 89

Answers (1)

user1122069
user1122069

Reputation: 1817

You are missing the part where you declare "currlstArr". You are setting the value of currlstArr inside the foreach, so, if t< 0 you have nothing set, otherwise, you have the value of .split. Your use of setAdapter itself looks fine. Try

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" };

Upvotes: 1

Related Questions