I have a scenario below, and was wondering if anyone had a good solution. Basically, I have a class which manages a custom ViewFlipper object. One of these views within the ViewFlipper instance consists of a custom ScrollView with custom rows (which reside in mRows an ArrayList of the rows). In the custom ScrollView class I have the loop...
for (CustomRow : mRows)
{
row.setOnTouchListener(this);
}
In the onTouch listener I want to be able to notify the top level view (the object that holds the reference to the ViewFlipper instance). What is the most efficient way to do this?
Related
Now I am implementing chat screen in an Android App.
the use of the adapter pattern of ListView seems to be the best one cell.
You know you need a cell of a different type of user messages, photos, videos, dates, announcements, etc in chat screen.
Conventional methods that I know of is two things.
In getView() method, create each time a new type of cell.
First of all, put all the item and ,in getView() method, adjust the UI layout by VISIBLE/GONE options.
The second method is better i thought, but this method is still a waste of memory and complexity to implement.
For UITableView of iOS generate multiple queue by the number of type of cell. It is efficiently in Multi-Item ListView.
there any easy way to implement as iOS?
Use RecyclerView instead of ListView.
Create xml file for each item view. Create ViewHolder for each file xml.
Inside Adapter of RecyclerView override getItemViewType() return view type correspond with it's position. Override onCreateViewHodlerwhich return ViewHolder correspond with view type. Finally, override onBindViewHolder bind your data to your layout.
Consider using this library JSQMessagesViewController its very flexible and scalable.
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.
So this one is probably very simple, but I'm having a bit of trouble figuring it out.
So I have a custom View, which is now running in an activity along with a standard TextView widget.
What I want to know is whether there is a way to update the TextView from my custom View class
Define a listener interface in the custom view. Define a setXxxListener() method in the view. Override the listener in the activity class. From the custom view, call the listener when needed. In the activity's listener implementation, update the TextView.
Such is the Java way.
In general, view classes should not make assumptions about other views running along. The object that manages both views - in your case the activity - should coordinate the data exchange between them.
I have created a compound control that I am reusing in multiple activities. This control contains a bunch of TextViews and Buttons, and most importantly a ListView. I define the XML in a layout file and in the constructor to this compound control, I inflate the XML as such:
String service = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(service);
inflater.inflate(R.layout.map_menu, this, true);
The layout XML contains a ListView, and also in the constructor this compound control will handle setting up the adapter (my adapter extends ArrayAdapter) and array for it, like so:
ListView tableOfContentsList = (ListView) findViewById(R.id.tocListView);
_layerAdapter = new LayerAdapter(context, R.layout.toc_layer_item, _layers);
tableOfContentsList.setAdapter(_layerAdapter);
This compound control is used in two activites - one of these activities calls another. No relation between the two activities is intended.
Here is my problem. When the compound control is created in the initial activity, the above code is called to set the adapter of this control. Then, when the second activity is created and navigated to, the constructor is called again on this second instance of the control. This seems to have a side effect on the first control located in the initial activity. The second control seems to overwrite parts of the adapter from the first control - because basically the first adapter will not be functional once the constructor to the second control is called.
It is my guess that since I am referencing the resource ID of the ListView in both controls, Android is removing the adapter from the first ListView when the second ListView is created - because it sees both ListViews as having the same resource ID? Is this possible?
I have had trouble before in this exact same case - where multiple compound controls are used in different activities (and multiple times in a single activity) - and the problem was due to inflating from XML layout. My solution to that prior problem was to get rid of the inflating from layout, and instead creating the objects through code. This was acceptable because those compound controls were much simpler and contained only two views - however I feel in the above ListView case, where my compound control has at least ten views in it, it is not an acceptable solution to define each view in code. I need the layout XML.
Has anyone ever experienced this sort of clashing behavior when using custom compound controls that are inflated from XML, and re-used in multiple instances?
From my understanding Android should create a new instance of the widgets each time you inflate the xml. Do you have any static members in you compound widget class?