Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to turn Text View display into List View display?? I was given the question

ID: 3742098 • Letter: H

Question

How to turn Text View display into List View display??

I was given the question below... and I have completed the code. Instead of displaying it as a list view, I did it as text view. How can I display it as list view (am not too sure about it)?

Question: You are required to implement an app that reads a text file and displays the text on the screen line by line using listview. You can copy and paste a text file of your choice into the folder raw/yourtextfile.txt.

//content_main.xml

//MainActivity.java

Explanation / Answer

1. Create List view

Add this to your XML file.

2. Add the below line to onCreate

3. Declare the following array

4. Change the line

to

5. Add the below lines

Better use built in Array adapter. For that, you need to have your data in array. Since data is in lisr, let's convert it into array.

String[] dataArray = new String[list.size()];

dataArray = list.toArray(dataArray); //Array is passed as parameter for jvm to understand the type of the array

Now, it will show you the list view. You can remove all text view related items from the code and the string buffer too. You can add action on list item as well.

In case of any doubts, please comment.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote