folks!
I need to make such layout: I've got listview and I need to put buttons on top and on the bottom of it, i.e. when user scrolls list to the end, he can see bottom button, and when user is on the top of list, he can see top button. But when user is 'in the middle' of listview, he can't see those buttons. I've got no idea how to do it. Thanks for help.
UPDATE
listView=(ListView)findViewById(R.id.listSearchResults);
LayoutInflater inflater=this.getLayoutInflater();
View header=inflater.inflate(R.layout.list_header, null);
btnBack=(Button)header.findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
btnBack.setEnabled(false);
listView.addHeaderView(header);
View footer=inflater.inflate(R.layout.list_footer, null);
btnForward=(Button)footer.findViewById(R.id.btnForward);
btnForward.setOnClickListener(this);
btnForward.setEnabled(false);
listView.addFooterView(footer);
First create two layout file. like as footer_layout.xml & header_layout.xml and add footerview-headerview in list view
LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout listFooterView = (LinearLayout)inflater.inflate(
R.layout.footer_layout, null);
list.addFooterView(listFooterView);
LinearLayout listHeaderView = (LinearLayout)inflater.inflate(
R.layout.header_layout, null);
list.addHeaderView(listHeaderView);
You can use addHeaderView() and addFooterView() on your ListView
Check here:
Android Dynamically load Listview at scroll end?
This is with the help of list's footer and header. Basically, you use addHeaderView()
/addFooterView (). Check all versions of the methods, since they allow you to have the view not being selectable.
Related
[When click on the button which is marked as circular line of image 1 then next functionality will be happen which is second image 2
is what you want to happen is that when you click the image button that row layer will hide?
You can add a layout at runtime using below snippet onClick of button.
LayoutInflater layoutInflater = getLayoutInflater();
View row = layoutInflater.inflate(R.layout.row, null);
ViewGroup main = (ViewGroup) findViewById(R.id.child_layout);
main.addView(row, 0);
R.layout.row is the row which you want to add on click of arrow.
R.id.child_layout will be an empty LinearLayout placeholder in your parent xml in which above row will be added.
You might want to look at various implementation of addView(), as it is overloaded with various parameters.
You can use removeView to remove the view as well.
There is one more option in which you can the add the row as part of layout set its visibility as GONE
e.g.
mainLayout.setVisibility(LinearLayout.GONE);
mainLayout.setVisibility(LinearLayout.VISIBLE);
And then you register or deregister click listeners.
I know how to add Ellipsized TextView in ListView item as the following code
android:singleLine="true"
android:maxEms="20"
android:ellipsize="end"
What i want is adding three dots at the end of listView as indication for reaching the last item in the listView. Check the link below to see what i want to achieve.
https://www.dropbox.com/s/69hpe6z112p0wa3/example.png?dl=0
Note: The items in the ListView are populated from database
Make a static view of 3 dots and add as footer to your List View as
View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
ListView.addFooterView(footerView);
Simply add footer view and create a the layout as you wish to display there at the end of your list.
View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
listView.addFooterView(footerView);
If you want to display it at the end of your last item than this approach is useful but if you want to display it all the time at the end of your list than you can add the footer view in your layout below the listview in your xml file
I'm trying to create something like editable UITableView on iPhone.
I added a button to add new items at the end of the list which would be the equivalent of the "+" button on iphone, this takes user to a list of items to add. My problem is that when they select one I don't know how to add it to the list.
<LinearLayout
android:key="application_preferences"
android:title="Applications">
</LinearLayout>
How can I append a view inside the LinearLayout programatically?
You can use addView to add a child view to a ViewGroup, but also consider just using ListView instead of a LinearLayout.
Your question is not very clear but if you try to add a view to the linear layout programmatically just use Layout Inflater
LayoutInflater localLayoutInflater =(LayoutInflater)getBaseContext().getSystemService("layout_inflater");
View myView = localLayoutInflater.inflate(R.layout.custom_layout, null);
final LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayoutID);
ll.addView(myView);
I'm trying to create a scrollable layout with an embedded list, similar to the Spotify application for Android one shown here (One image at the top followed by a list and the whole layout scrolls). I'm aware that the Android developer guidelines state that you shouldn't put a ListView inside of a ScrollView layout so I'm wondering how this is accomplished. Do I need to make each list item manually using layouts and TextViews?
Yes as the List view has default scroll able functionality . If you place a listview inside the scroll view . The list scroll will hamper.
To Avoid such thing , list view has the concepts of header and footer views.
You can add n number of header and footers to the list.
Below is a sample code snippet how to add header/footer by inflating any xml layout to it
LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout listFooterView = (LinearLayout)inflater.inflate(
R.layout.footer_layout, null);
list.addFooterView(listFooterView);
LinearLayout listHeaderView = (LinearLayout)inflater.inflate(
R.layout.header_layout, null);
list.addHeaderView(listHeaderView);
There is a ListView and list_row xml which includes LinearLayout with background image.The requirement is to show the image in first row of ListView when loading data.And subsequently show and hide the image when tap on the rows of ListView.
ViewGroup vg = (ViewGroup) ListView.getAdapter().getView(0, null, null);
TableRow selectedRow = (TableRow) vg.getChildAt(0);
LinearLayout ll = (LinearLayout) selectedRow.getChildAt(0);
ll.setVisibility(View.VISIBLE);
I used the above source code and try to do it.But this is not working and does not return any null objects.Show and hide part is working on using ItemClickListner.But I need to show the image when loading data.
I try to do it in Adapter class and I was able to show the image.But I couldn't hide it when tap on other rows of ListView.How can I fix this problem?
Thanks in Advance.
For this, I would suggest you to use ListView.addHeaderView(v) method. It will allow you to add a view as header of ListView (which will always be on top of other list items). Afterwards, when you've implemented ItemClickListner, simply call ListView.removeHeaderView(v) to remove that header view from list.