Question

Android: fill spinner with items in text file and output is truncated

My source file for fill spinner in my Android form it's country txt.

If using this version the items in the spinner are stopping and truncate to country: "French Polyn": http://www.filesnack.com/files/ctjlom8p

If using this other country txt file: http://www.filesnack.com/files/ct9sr3fn

The spinner is populated correctly ... why ?

<Spinner
android:id="@+id/my_spinner_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:spinnerMode="dialog" />

Import the country txt file in spinner with:

String path = "http://www.remoteHost.com/public/country.txt";
URL u = null;
try {
   u = new URL(path);
   HttpURLConnection c = (HttpURLConnection)u.openConnection();
   c.setRequestMethod("GET");
   c.connect();
   InputStream in = c.getInputStream();
   final ByteArrayOutputStream bo = new ByteArrayOutputStream();
   byte[] buffer = new byte[1024];
   in.read(buffer);
   bo.write(buffer);
   String s = bo.toString();

   final Vector<String> str = new Vector<String>();
   String[] line = s.split("\n");
   int index = 0;
   while (index < line.length) {
      str.add(line[index]);
      index++;
   }
Was it helpful?

Solution

I guess this is because you limit your buffer to 1024 Kbytes. The first file is more than 2048, the second one is about 850 only. This could be the reason.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top