I have custom ListView item with ImageView and TextView. TextView contains HTML string with urls and some regular text. Im my adapter I have code similar to
tv.setText(Html.fromHtml("<a href='http://google.com'>google</a>"));
tv.setMovementMethod(LinkMovementMethod.getInstance());
and this works great but onListItemClick isn't executed when I click on item outside url, whole item looks like inactive.
When I click on url I want to fire default action form urls and when I click on regular text or on ImageView I want to execute onListItemClick is it possible?
Second question, is it possible to start activity using start some activity?
You can't make an intent form an anchor.
It's ok and recommended that you use onListItemClick (it saves you a lot of work), and if you want to open the link in the browser (without using a webview) you can use this an intent, this is an example:
Intent myIntent = new Intent(Intent.ACTION_VIEW,ContentURI.create("http://www.google.com"));
startActivity(myIntent);
Hope this helps.
You need to specify a callback for each of the views that you wish to select. I believe you have three different items: The Listview object, which contains a TextView and an ImageView.
If you would like to have different behavior for each different piece, you need to create a callback for each different piece. You can set a callback in the XML declaration of the view by setting
android:onClick="myCallback"
http://developer.android.com/reference/android/view/View.html#attr_android:onClick
Related
Some items in the list, if clicked, will hyperlink to a URL.
If there is no URL for the associated item, then clicking it should do nothing.
Should I use a ListView, or is there something better?
You can make a Listview layout with single textview
Use Arraylist to hold basically 2 things
i. The title of your Hyperlink
ii. The Url it would redirect to
Set a Adapter to your ListView
Set a ClickListener to your ListView
When a Particular item is clicked you can the postion of your listView item to get content in a Arraylist
eg.
arraylist.get(postion).name
arraylist.get(postion).url
Now you can just start a WebView using Intents
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(browserIntent);
Also if you have too many items to be displayed, I would recommend using RecyclerView
I suggest you to use RecyclerView, so in each result item view containing a TextView with attribute android:autoLink="web", take a look in android:linksClickable attribute as well.
I have a ListView in my app. and when user clicks on each item of it, I want a small ListView with 3 items appear to the user.Could any one suggests me How can I implement this small list?
Since you want to always show the same items, you could use a popup activity (a custom dialog) when the user clicks on the list.
The layout of this popup activity will only have a listview, populated in the onCreate() method.
If you want to use ListPopupWindow you can see this example:
Example on ListPopupWindow
To open another activity when an item is selected add something like this in the onItemClick method in ListPopupWindowAppActivity class:
Intent intent = new Intent(getApplicationContext(), AndroidFirstActivity.class);
startActivity(intent);
Keep in mind that ListPopupActivity is available since Api 11, so if you want to target earlier apis you can either use my first option (custom dialog) or the android.widget.PopupWindow. There are several examples for android.widget.PopupWindow, one can be found here:
Example of PopupWindow
I have completed the Hello Views tutorial from android developers (http://developer.android.com/resources/tutorials/views/hello-listview.html)
I understood the concept, but it doesn't fit my project. I'm trying to make a list and when clicked I want it to open a webView with different URL's depending of which item is clicked.
I can't figure out which code I need to use...
you just need to set up an OnItemClickListener for the listView:
http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html
Declare a new Webview at the top then within this OnItemClickListener set up a switch statment to assign the URL to the WebView depending on which item in the ListView was clicked. Then out side of the switch statment, but inside the OnItemClickListener, call on the WebView.
Hope this helps.
I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.
i have listview and i call intent from the listview onitem selected method
but when i get linkfy textview in my listrow than i am not able to call intent from the onItem selected method.
Any suggestion would be helpful to me.
I'm a little short on detail here, but it sounds like you want your text to look like a link while still using the list view's onListItemSelected method to handle clicking on the link.
I haven't used 'linkify' in a textview before but I suspect it might be overriding the click/touch event that the list would otherwise be using (to act as a link instead).
If you still want it to look like a link while using the onListItemSelected method, you could easily modify the textview's text color to blue instead, though underlining the text might be a bit more difficult to achieve.