I've got an activity populated by TwoLineListItems, and I'd like to be able to click them to go to another activity and show a more in-depth view of the information associated with the TwoLineListItem. Do I just use a standard OnClickListener and declare each TwoLineItemListener as clickable?
TwoLineListItems are intended for use in ListViews. In order to implement a clickHandler for a listView you would override the onListItemClick method.
If you are not using a ListView, and your TwoLineListItem is a child of a different layout, I would recommend using a simple Linear or RelativeLayout instead.
Related
I searched allover but couldn't find any clear answer. I have a ListView declared in A customView and I would like to open another ListView when clicking on an Item.
I managed to do that by changing the adapter each time I click on an item on the Main ListView and show a pseudo new ListView. However this is not a stable solution.
I would like to know how can I instantiate a new listView without using intents or without having to change the adapter each time I want a new list output. I would want to create an entirely new ListView without direct connection to the initial one.
Can you try using ListFragment with FrameLayout in layout file? and just switch fragment when click on list item
I found the solution. I created in the CustomView several LinearLayouts for each listview one root layout. I have also created an individual class for each listView and used the same CustomAdapter and ViewHolder throughout. What I additionally used were interfaces that I declared in each List View class, with a method that tracks the row number. Based on this I implemented all the interfaces in the CustomView and listened to the clicked rows. At last, I then created animation methods and played with the visibilities.
By the way, instead of setting the List views to INVISIBLE i set them to GONE, hence there are quite manny the GPU doesn't need to recalculate the layout bounds.
Hope that helps cheers.
The method that i Place in the customView init() looks like this:
The interface listener must be implemented on "this" context of the CustomView, otherwise NUllPointerException hence the ListView doesn't know where to listen too.
I want to create a custom view with some text and two buttons all on one line. I need to be able to add multiple (any number) of these views to an existing layout dynamically (needs to be able to scroll). I want to pass a custom object to the view and set the text and buttons. I need access to the button event handlers from the activity. I've looked a little into custom views but I'm still at a loss for how to do what I want. I'm used to .NET custom controls, and I'm looking for the same effect. Any help or example code would be greatly appreciated.
What you want is custom compound view. You should write you own class (usually extending one of the layouts) and whole behavior, inflate the layout the way you want etc.
More of it: http://developer.android.com/guide/topics/ui/custom-components.html
This one helped me a lot too: http://javatechig.com/android/creating-custom-and-compound-views-in-android-tutorial
If you use list activity or list fragment, you will automatically have the many features you have asked for. You only need to create a adapter class for your listview. You can define your layout for your row view(buttons, text etc..) Try to look at the examples on the web for cusom adapter and lists.
Anyone knows how the center part is being listed? I tried using listview but it does not have a space large enough for the image
You need to customize the normal behavior of the ListView. The layout you see inside each row, is a separate layout file prepared, that contains some TextViews, ImageViews, and that layout file is inflated as a row of the ListView.
Check out this example: http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92
Very nicely explained how we can customize a ListView.
I think you would be able to use a scrollview then just add some views and layouts inside it.
If you create you own list adapter you can inflate all kinds of views inside a normal listview
extends ArrayAdapter<Object>
And overwrite the getView method
You can have look at PintrestListViewAdapter which is opensource
Check out the Implementation demo HERE
hi I want to use a listview (probably) is it possible to fill each entry with say two buttons two text areas, and have them laid out with realtive or linear layouts?
I have used a scroll view with layout inflator to achieve this at the moment, but I'm thinking listview would be better maybe?
yes you can. you need to use a custom list view for that. making an activity by adding a listview in it and then referencing another xml to that listview using an AAdapter so that every element of the listview has the layout of the second xml file. this tutorial should help you understand the idea.
Yes you can place any widgets for the particular List Item for your listview.
For defining that kind of ListView, you have to define a custom adapter, follow the below steps:
Define a one row file for the list item, say for example, RelativeLayout with 2-3 TextViews.
Define a class by extending BaseAdapter.
Inflate the XML and do display operations inside the getView() method of this class.
Set this adapter to the ListView.
I have defined two views ExampleView1, ExampleView2, ExampleView3 and ExampleView4 in resources.
In my Activity I have an empty ViewFlipper. Based on doing some logic I want to add either ExampleView1 and ExampleView2 to the ViewFlipper and show the view.
Later I want to add based on internal logic either ExampleView3 and ExampleView4.
How do I do this? Is there some tutorial or can someone help me with example code?
Just use the addView method, which ViewFlipper inherits from ViewGroup. If your views are custom ones, you will have something like this:
flipper.addView(new ExampleView1());
On the other hand, if the views are defined inside an XML layout, you will have to inflate them first:
View view = LayoutInflater.from(context).inflate(R.layout.your_view, null);
flipper.addView(view);