I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like to move up to a real ListView, but I'm just not finding the sample/explanation that I need to take that next step.
I have successfully reproduced the HelloListView sample, starting with the hardcoded string array, and moving to a string array defined in my res/values/strings.xml. I've taken one small step toward my goal by adding my HttpClient code to retrieve a set of data from a service, parse the results into a String Array and feed that into setListAdapter() such that my text and links show up as text-only in ListView items.
I want to move to the next step which is to make each "row" in my ListView launch the browser to the URL contained in the data, either by
(A) clicking anywhere in the row, or
(B) clicking a hyperlink displayed within the row data
For option (A), it appears that I need to have my onItemClick() method issue an intent that launches the browser. That's straightforward, but I don't get how to associate the URL with the item (currently its just one part of the string content for each "row" of text). How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL? Do I need to replace my String Array with an array of custom objects?
For option (B), can I use Linkify? It seems that my string array elements get converted to individual TextViews (inferring from the way the Toast text is generated in the HelloListView sample). Do I have access to that TextView to run Linkify against? Do I need to replace my String Array with a TextView Array and run Linkify myself? Am I completely off base?
Thanks to anyone who can help explain back to me what I'm trying to do, in a way that helps to find my way around the SDK, samples and other helps!
How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL?
Use a regular expression (java.util.regex) to find the URL.
For option (B), can I use Linkify?
Yes.
Do I have access to that TextView to run Linkify against?
Yes. Override getView() in your ArrayAdapter. Chain to the superclass and get your TextView from the result of super.getView().
Even better would be to use Linkify on your strings before putting them in the array in the first place.
Do I need to replace my String Array with a TextView Array and run Linkify myself?
No, and that is really not a good idea. Here is a free excerpt from one of my books that goes into more detail on tailoring the individual rows of a ListView, in case this helps.
Related
I'm currently doing a project from one of my subjects in my university. I'm about to do an attendance app that checks if the professors are present, late, or absent in the room based on the schedule. I made an app in an android studio which uses radio groups and radio buttons that will change the text in the text view which will show if the professors attendance status. I'm thinking of making a button that will upload the text views with the attendance statuses to a website which holds the data(database).
I'm not used to programming in the android studio that is why I would like to know if a way to upload the text views on a website. Thanks
It's quite simple, You have to create Weg api that you can call from the android mobile application and pass the current status of the professor or the whatever you want to pass on the server. That api will update the database as per whatever you have passed from the mobile application.
Also, One more thing that you can not pass the text view, you just need to pass the text of that view.
I hope, you will get answer from this.
Happy coding...
Assign value of textview to a string variable.
And use this string in your api to pass data.
For example if you have a textview with name teacher, you can get its value using this line.
String st_teacher = teacher.getText();
Now use that st_teacher value in your api to upload data.
i am a novice in android and i was trying to make an application that has two fragments, one with a listView with topics which when one is clicked it opens a topic description in the other fragment. i would like to know how to also store the large string for the description
If the data is dynamic you can store your topics and desciptions in a sqlite database. You have several possibilities:
You load the topic and description at the start and give over the description with a method or an interface to the second fragment.
You store the data in a database and give every entry a unique id and use a method or an interface to communicate with the second fragment and put the id to it. And then you use the id to get the description from database.
UPDATE #1
You can use arrays in your resource files. Create two arrays. One with your topics and the other with your descriptions. But the topics and descriptions have to be in the same order. For example the description of the second topic have to be on the second position in its array. Now you use the first array for your listview and the second(with the descriptions) in the description fragment. The "setOnItemClickListener" method of the listview have the position as a parameter. This is the same as the position of the topics and desciption in your arrays (when you dont resort anything).
I want to show data in a sensible form for my movie database app. The website I am using to extract data from is www.omdbapi.com. I have already created a code that extracts the title and year of the movies and displays it in a ListView form which contains items that are all clickable to another activity. I would like each activity that the ListView item clicks to to display the movie information under different headers etc.
I have been stuck on this issue all day. I'm new to coding and have no clue what most processes are called etc. Im not asking for the entire code, just instructions on what to do because I am stumped. I would be very very grateful.
Thank you.
Depending on the format the response is formatted you would either use (probably) an xml parser or a JSON parser and grab the info between specific xml tags or the specific keys within the JSON output.
There are thousands of examples of both methods. If you can get the title to display, then you already know how to get the other elements.
I am performing a search over Strings in an ArrayList. If the Term is found I need to highlight that term and return the a string with the word where the term is present plus a word before and after that word!
Example:
Term = “some”
Searched String = “This is my awesome test String!”
Result = “my awesome test” (“some” should be highlighted here)
First off I am useless with RegEx and wouldn’t know where to start and secondly I’m not sure how to highlight text in a ListView, there are 3 TextViews per Row and I pass an Array with Data objects to the Adapter. Can I just give the Data Object Spanndable’s for highlighting?!
After some trial and error and some help i got this which seems to do the trick
(^|\S*\s)\S*term\S*($|\s\S*)
I'm making a fake command-line system for a fun app, and I want to show the input and output in the same TextView, like this:
>something
>something else
>even more stuff
>etcetera.
I already figured out how to store the text from the EditText into a string and add \n and >, but I can't use strings for the whole thing: to avoid clogging up RAM, I'd like to delete lines after, say 50? I figured that would be much easier to do using Lists.
However, this doesn't work:
log.setText((CharSequence) logText);
But what will?
This method :
http://developer.android.com/reference/android/text/TextUtils.html#join(java.lang.CharSequence, java.lang.Iterable)
return a string composed of each element (either cast as a string or the toString value is used) separated by the delimiter in between each element. You can therefore easily concat all your items in one String.
You can also use http://developer.android.com/reference/java/util/AbstractList.html#subList(int, int)
to limit the count of items in said list.
From your question I assume logText is a List of some sort, therefore you can call
log.setText(TextUtils.join("\n>", logText.subList(0, 50));
Maybe you can put all your strings in a list, an each time you add one, recreate a single string from the list which contains all your items, and affect it to your textview.
You could use a ListView without a separator and populate it using an ArrayAdapter.
That way you wouldn't have to worry about memory, and the user could easily scroll through previous commands.