0

I have list.php file from my server it gives me like 20 lines of file names how can I put each file name separately inside ListView in Android.

2017-05-11_15-03-14-70-channel1-projecttsd2013-1618032742.3gpp
2017-05-11_15-15-39-58-channel1-projecttsd2013-1618032742.3gpp
2017-05-11_15-15-39-59-channel1-projecttsd2013-1949843892.3gpp
2017-05-11_15-15-39-60-channel1-projecttsd2013223240350.3gpp
2017-05-11_15-15-39-60-channel1-projecttsd2013451577137.3gpp
2017-05-11_15-23-32-25-channel1-projecttsd2013-1618032742.3gpp
2017-05-11_15-30-00-39-channel1-projecttsd2013-1618032742.3gpp
2017-05-11_15-30-46-53-channel1-projecttsd2013-1949843892.3gpp
2017-05-11_16-46-16-37-channel1-projecttsd2013-1396509740.3gpp
2017-05-11_16-55-39-56-channel1-projecttsd2013-1396509740.3gpp
2017-05-11_17-00-10-317-channel1-rafogasparyan92086898.3gpp
2017-05-11_17-32-30-48-channel1-projecttsd2013-1396509740.3gpp
2017-05-11_17-34-26-97-channel1-projecttsd2013-1396509740.3gpp
2017-05-11_17-36-50-91-channel1-projecttsd2013-1396509740.3gpp
2017-05-11_17-41-30-74-channel1-armtab17-1593149344.3gpp
2017-05-11_18-07-10-93-channel1-projecttsd2013-1396509740.3gpp
2017-05-11_18-09-23-35-channel1-projecttsd20131261788243.3gpp
2017-05-12_14-22-33-17-channel1--518666646.3gpp
2017-05-12_14-58-01-58-channel1-projecttsd2013-518666646.3gpp
2017-05-12_15-01-15-43-channel1-projecttsd20131215499264.3gpp
2017-05-12_15-07-36-54-channel1-projecttsd2013671830229.3gpp
2017-05-12_15-08-25-06-channel1-null125424439.3gpp
2017-05-12_15-08-33-18-channel1-null-431222664.3gpp
2017-05-12_15-09-01-82-channel1-null1563152754.3gpp
2017-05-12_15-09-29-24-channel1-null-972865152.3gpp
2017-05-12_15-25-08-04-channel1-projecttsd2013-518666646.3gpp
hel.3gpp
hello.3gpp
IMG_20100128_192814.jpg
sound.3gpp
sound1.3gpp
test.3gpp

Is it possible those are the names from http://ip/android/list.php shows in the browser?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    well i don't know how can you help me and of course the list gonna grow so i don't know the string names –  May 12 '17 at 12:08

2 Answers2

0

Well I guess you have String which you have to make List<String>.

So you can simply use String.split() method.

String example = "2017-05-11_15-03-14-70-channel1-projecttsd2013-1618032742.3gpp
2017-05-11_15-15-39-58-channel1-projecttsd2013-1618032742.3gpp
2017-05-11_15-15-39-59-channel1-projecttsd2013-1949843892.3gpp";
String lines[] = example.split("\\r?\\n");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, lines);
listView.setAdapter(adapter);

UPDATE

In case of "a<br/>b<br/>" just change split to this line

String lines[] = example.split("</br>");
Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56
  • 1
    the list gonna grow so i don't know all string names –  May 12 '17 at 12:07
  • You want to listen on the php file changes or just parse the list at the current moment ? – Timo May 12 '17 at 12:09
  • 1
    No he means that the output from the server could be more lines than he mentioned – Denny May 12 '17 at 12:10
  • @Eazyz emm...I guess you make some request to server and getting response. Response in that case is example string. Or you really have stream? – Andrey Danilov May 12 '17 at 12:12
  • So he can use this code, I will just keep the array lines ArrayList is useless here. You just have to request your url get the result parse to an array give it to your adapter (of your listView) and Voila ! – Timo May 12 '17 at 12:12
  • 1
    yup they are steaming but in another ip address but that is not my issues i just want to put every line seperatly inside listView I can't seperate it thats the issue –  May 12 '17 at 12:16
  • 1
    Timo and how i convert it into String ? and seperate the lines –  May 12 '17 at 12:17
  • String[] lines =your_request_result.split("\\r?\\n"); give you a tab which each element is a line. You just have to use a basicAdapter which you give the array to display. Do you have already work with adapter ? (Maybe I should ask this first) – Timo May 12 '17 at 12:20
  • @Timo you are right, its not necessary. Just usually work with Lists and RecyclerView. Will update post =) – Andrey Danilov May 12 '17 at 12:49
  • 1
    @DEADMC I don't have all the string like u wrote the app its call recorder it records the call and upload it into server i'm creating another app that i want to get the string names so i can add it with the right ip to steam each file seperatly –  May 12 '17 at 13:14
  • @Eazyz you showed in your question response from server which you have to show in ListView. So you just work with that *response*, no? What is difference between example string and response? Looks like you have to clearify the question. – Andrey Danilov May 12 '17 at 13:20
  • yea yea i got String from the server but like this a
    b
    now how i can separate a from b from c every line separatly so i can put my http://999.999.999.999/hello/a.3pgg to steam it
    –  May 12 '17 at 13:44
  • 1
    it worked thx but i have another text from php file and i cant put it on the listView it shows as 1 big text on 1 line in listView –  May 13 '17 at 06:36
0

I assume you get a string from your PHP srcipt lets call it requestStr.

String[] lines = requestStr.split("\\r?\\n");

Now you have your array you can implement an adapter like this https://stackoverflow.com/a/43893273/3289338 and give the array as parameters

You just set this adapter to your listView and it's over

It's really basic, if this is for an app in production I would use a better implementation of the Adapter with custom views and ViewHolder pattern

And just for information if not already the case when you use the network to request your php script, you have to do this in an other thread than the UI-thread How to fix android.os.NetworkOnMainThreadException?

Community
  • 1
  • 1
Timo
  • 497
  • 10
  • 21