My requirement is like, I have a webservice url where from I load the datas into tree view. u communicate webservice load all first leve menus. Later when I click on first menu, i again communicate webservice to get the second level node data, my webservice data has an attribute nodetype = "group" or "item" which means if it has sublevels It says group else "item". I can use this to show + or - mark in my treeview. I have gone through the treeview in google Code. They load all the data at once which does not suit my reuquirement. Please need some help on logic building. If any one has already done such thing it would be really great if you can share the code here or mail me at colddropz#gmail.com.. Thanks in advance!
You can study this library: https://github.com/bmelnychuk/AndroidTreeView to get your required tree-view. It's a N-level tree with supporting custom styled node. You can use it as following:
1) install: compile 'com.github.bmelnychuk:atv:1.2.+'
2) build tree-view:
TreeNode tree_root = TreeNode.root();
TreeNode parent = new TreeNode("node-name");
TreeNode child0 = new TreeNode("child-node-name-1");
TreeNode child1 = new TreeNode("child_node-name-2");
parent.addChildren(child0, child1);
tree_root.addChild(parent);
3) add tree-view to layout:
AndroidTreeView treeView = new AndroidTreeView(getActivity(), tree_root);
containerView.addView(treeView.getView());
You can customize the node-view to show + or - mark in your treeview with extending TreeNode.BaseNodeViewHolder
Related
I am working on a Android TV app for quite some time now and I have come far while working on it. I am trying to develop an app like popcorn time but it's for Google nexus TV box.
The problem where I am stuck in, is really simple but even after a lot of effort I am still unable to figure out the solution.
I am fetching the json data from my database which has all the movies details and links and this works perfectly fine.
Over all app view
Now those who have used the you tube app on Android TV must have noticed that it was built on leanback and as you scroll down in a listrow more cards are added into a row and likewise the app made the json calls to fetch more data according to the category we are scrolling in. (that's what I want to do)
Right now it is impossible, if I request for large data it takes a long time to fetch everything from the server so I have devised a way via which I can make json calls on scroll but I am unable to present them in a listrow at runtime.
To add items to a presenter;
CardPresenter channelCardPresenter = new CardPresenter();
ArrayObjectAdapter channelRowAdapter = new ArrayObjectAdapter(channelCardPresenter);
channelRowAdapter.add(new Movie("Movie Title"));
HeaderItem header = new HeaderItem(0, "My Channels");
mRowsAdapter.add(new ListRow(header, channelRowAdapter));
Of course this may only work for the first time you're creating the UI. Future times may not do this. In my app, https://github.com/Fleker/CumulusTV/blob/master/app/src/main/java/com/felkertech/n/tv/LeanbackFragment.java, I create a method that will be called each time I want to do a full redraw of the app:
public void refreshUI() {
prepareBackgroundManager();
setupUIElements();
loadRows(); //Generate and populate all the rows
setupEventListeners();
}
I have been working with android TV Leanback library from past 7 or 8 months. And I have developed my own presenter class via which you can load more cards dynamically on scroll, but its not possible using Leanback Library, ListAdapter updateds a single row and than move to next category to update it's cards. which take time on run time.
I have used the below answer to create my own presenter class. The Trick while implementing endless loading on scroll is that you have to create two AysncTasks.
Have a look at at post 34
Lazy download images into gridView
it will a little time taking but you will get the idea.
I'm looking for a view known as LongListSelector on the Windows Phone. It's a list view with group headers. Tapping a group header displays only a list of groups. Tapping a group on the list of groups hides the list of groups and scrolls the view to the selected group. It's a very useful way of groupping long lists with easy navigation between groups. If there are alternatives fit for the same purpose that would be also great.
You can do this easily :)
The first thing you need to do is make sure your data source is a collection of collections. I would suggest an ObservableCollection> if you want maximum binding goodness. Then we can construct our listView as follows:
var listView = new ListView ();
listView.SetBinding (ListView.ItemsSourceProperty, "Data");
listView.ItemTemplate = new DataTemplate (typeof (MyCell));
listView.GroupHeaderTemplate = new DataTemplate (typeof (MyHeaderCell));
listView.IsGroupingEnabled = true;
listView.GroupShortNameBinding = new Binding ("Title");
In order, we first bind in our data, I am assuming the BindingContext here will be inherited from the page. Our data should be the collection of collections already mentioned.
Then we bind in our ItemTemplate as normal, we make a GroupHeaderTemplate, this will be the template shown in the list during normal scrolling. Next we enable grouping to tell the list to use the data as a grouped collection rather than a flat list.
Finally with all that done, we provide a binding for the GroupShortName. This binding is run against the collection for each group to grab out a string (or an object that will have ToString called on it) to produce the jump list as you showed in your screenshots.
For performance reasons you may want to ensure the ItemsSource is not set until everything else has been set to avoid the ListView attempting to realizing Cells in a partially configured state. This will not actually result in bugs, it just forces the ListView to do more work.
i wish to show a listView on a PreferenceActivity similar to what the android OS wifi-settings has for the list of networks (example here , on the bottom area of the image) .
however , such a thing isn't availabe , so i've created a new class that extends Preference , and what i returned in the onCreateView is just a ListView instance .
it worked , but the listView has a constant size of about a single item no matter what i do to its layoutParams and no matter what i do to the adapter . even if i set the adapter inside the onCreateView , it has the exact same size .
not only that , but the listView cannot be scrolled , even though it is clear that it has multiple items within it .
i would , of course, want to use the same text size standard as on all of the preferences , to give a native feeling.
can anyone please tell me what can be done in order to make it work well?
btw, the app should work for android API 10+ (minimum 10) .
In case you are going for the same appearance / behavior, you should stay with the plain PreferenceActivity implementation, and add the new preference items into the "list" dynamically from code (eventually with custom renderers).
A basic implementation of such display would be:
/**
* This variable stands for the items with which you want to populate the list
*/
final HashMap<String, String> networks = new HashMap<String, String>();
final PreferenceCategory cat = new PreferenceCategory(getApplicationContext());
cat.setTitle(R.string.wifinetworks); // holding "Wi-fi networks"
for (final String networkTitle : networks.keySet())
{
final Preference pref = new Preference(getApplicationContext());
pref.setTitle(networkTitle);
pref.setSummary(networks.get(networkTitle));
cat.addPreference(pref);
}
Edit: For adding custom components to an existing PreferenceActivity, you should give a try to the addContentView method. From within onCreate:
final LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
addContentView(buttonBar, params);
ok , the answer would be to use setContentView to whatever layout you wish (including any views you wish) , add there a listView for the preferences , and for this listView , call bind and setAdapter.
i've found this solution by looking at other solutions, like this one:
http://kmansoft.com/2011/08/29/implementing-long-clickable-preferences/
I wrote a class similar to .NET GridView for android but my mind went blank for one action! when I loop through rows (or data whatever) I want to fire an event which includes selected row on every row. You can think as if you are reaching each row separately with helping by rowdatabound on .NET.
for (int m = 0; m < this.columns.length; m++) {
do some stuff
fire()
}
Do I need to create a new thread or listener? If yes how do I do these and how do I catch it on the otherside? Please give me an idea.
with this codes which I wrote below, I can create a gridview and display it without any problem. I need to get every rows one by one but how?
DataGrid dgSiparis = new DataGrid(this,lnSiparis,dt); //CREATING THE DATAGRID, argumants: context, linearlayout, a class named datatable which runs similar to DataTable on .NET, dt object has rows)
dgSiparis.setDataBind();
The answer:
create an interface for listener
implement your class with it (for this example DataGrid class will be implement it)
set it where you loop through rows
catch the listener you create on the instance class (for this ex dgSiparis)
There are no events in Java, instead it uses Observer - Listener pattern. Have a look at this article for details:
http://www.vogella.de/articles/DesignPatternObserver/article.html
I have implmented pagination and it display 5 records per page. Now suppose I am on page 3 and click 3'rd element then 3'rd element of page-1 is selected.
I am not able to figure out problem as I always create new list object while setting data.
I used below code
temp = new ArrayList();
this.someListAdapter = new SomeListAdapter(this, R.layout.row_facet,temp);
setListAdapter(this.someListAdapter );
Below is signature of SomeListAdapter class.
public class SomeListAdapter extends ArrayAdapter<VoNeighborhood> {
}
Please help....
There really aren't enough details here about how you do pagination with your ListView.
So I might guess you're overriding onListItemClick and using the position variable it sends you, but you then don't take into account the page you're on?
Alternatively, just don't use pagination as you have an infinite canvas to scroll your list within — I don't think I've recall seeing an Android app so far that uses pagination!