2

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.

2
  • 1
    Fix that horrible formatting. Commented Nov 5, 2015 at 21:37
  • I was not able to set the received values to listview ? Commented Nov 5, 2015 at 21:42

1 Answer 1

1

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" };
Sign up to request clarification or add additional context in comments.

2 Comments

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; String s=Integer.toString(t); for (int i = 0; i < persons.length; i++) { String currlst = persons[i]; currlstArr = currlst.split("LLLLLLLLLL"); }
I was not able to set the received values to listview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.