I'm looking for a way to update a layout's content with a new view. Is there any way to easily do this. It would be similar to how tabs work, but I don't want to have to get into extending the current tab structure if I don't have to.
The final result would be a few buttons that would switch the content in a specific linearlayout for each button.
Any help?
Have a look at ViewSwitcher. This is designed to help with the kind of things you are suggesting.
If you want the contents in entirely different layout files, you can use a LayoutInflater and add the inflated view to the parent view.
Related
I want to use this kind of UI in my Contact Android App. The picture shown resizes itself when we scroll down much and the Name 'XYZ' finally become the title of the action bar. Also how can I put textview over imageview?
What you're looking for is CollapsingToolbarLayout.
The general approach to this kind of animations is to use top level CoordinatorLayout which contain two children: the first child is the "collapsible" content, and the second is "body". The general hierarchy looks like this:
CoordinatorLayout
|-AppBarLayout
|-CollapsingToolbarLayout
|-Toolbar
|-ScrollView
The second child must not be ScrollView - use any ViewGroup that suits your needs, and just add the following attribute to its description in xml:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
the above string resource should map to AppBarLayout.ScrollingViewBehavior (just use android.support.design.widget.AppBarLayout$ScrollingViewBehavior as this resource's value).
There is very good tutorial on this kind of animations on Codepath.
Within my layout I have set a Include Other Layout. this layout schould in his turn show a listview with items loaded from the web (my webserver)
the only problem is: the items don't load in because the class that holds the code to load the items isnt called on because im using a Include Other Layout meaning only the layout is called and not the functional code from any .java files (classes)
leaving me with a blank page...
is there a way to make a call upon the class containing the code for the layout i have included?
<include/> tag is only for including only the view into another layout. It can be very useful if you use a common view everywhere. A ProgressBar can be an example. You can include ProgressBar everywhere you want. But it is just a UI.
If you also want the functionality you should use Fragments. Actually Fragments are exactly for what you describe.
Here is the tutorial from Android Developers official website
http://developer.android.com/training/basics/fragments/index.html
Instead of moving views in a current layout, I was wondering if i could instead load a different layout whilst the program is running.
For example in the on create i would use:
setContentView(R.layout.layout1);
and then in an on click listener i would use:
setContentView(R.layout.layout2);
I say this since I am using a custom dialogue which prevents me from producing a dialog to overwrite it. I have attempted it but so far have only received errors. I would really like to know if this is possible.
This is possible, but risky and not recommended for a final product. The problem is, you cannot access already defined views once you have switched views. You need to assign them all again for the new layout. So once you switch the content view, re-initialize all of your views and anything that references the old layout. Calling a view from the old layout will cause a crash or error message.
Like CodeMagic said, it is best to use fragments and the FragmentManager for this. And really, this is not a stable way to produce good code. I recommend using separate fragments and using backstacks and such so that not only will your game work, but you can easily navigate back to the original fragment, rather than use makeshift code that may barely work.
After setContentView(R.id.yourLayout) is called, you need to re-instantiate all of your other views. So like say you used an ImageView view to show the color changes, well you need to instantiate that ImageView after you setContentView(R.id.yourLayout) so that it pulls from the new layout, and does not reference to the original layout.
Example:
ImageView imageView;
public void onCreate(Bundle b){
super.savedInstanceState(b);
setContentView(originalLayout);
//Instatiate all of your original Views.
imageView = (ImageView) R.id.yourImageView;
}
public void onButtonClick(View){
setContentView(newLayout);
imageView = (ImageView) R.id.yourNewImageView;
//All other views
}
If you need an example of the fragment manager solution go here: https://developer.android.com/training/basics/fragments/creating.html
and look through some of their examples on how to properly do what you are trying to do.
I am learning android development and i am kinda stuck here. I want to create a friend list screen like shown in this picture.
What kind of activity should i use? Is there any available resources similar to what i want to achieve?
Thanks!
you can use ListActivity , also check out tutorials on lists, for example:
http://www.androidhive.info/2011/10/android-listview-tutorial/
http://www.vogella.com/tutorials/AndroidListView/article.html
you can find mire tutorials on google.
also you can use a regular Activity class with listView in the layout file
Use list view and custom adapter to populate the list view...
Listview should extend to the bottom but limit it just above the Type a name edit text and button.
Custom list view should contain linear layout horizontal in that include checkbox, Textview and Button
For type a name and Add use linear layout horizontal
Use listView with custom adapter , for array use arrayList<,friends,> sure you have to create friends class, in xml file put ListView then below that button and TextView
I've been searching for this topic for a while, and can't find enough resources or tuts about scrolling a PagerTabStrip. I'm using the FragmentStatePagerAdapter and populates the PagerTabStrip with getPageTitle(int position). I'd like to know how to make the titles scrollable. I'd like to scroll the titles without affecting the view by the time I stop or select into a specific title, then that's the time the view gets updated. I've been thinking to use HorizontialListView but not sure how to start. Hoping to learn from you. Thanks.
Found this on docu:
PagerTabStrip is an interactive indicator of the current, next, and
previous pages of a ViewPager. It is intended to be used as a child
view of a ViewPager widget in your XML layout. Add it as a child of a
ViewPager in your layout file and set its android:layout_gravity to
TOP or BOTTOM to pin it to the top or bottom of the ViewPager. The
title from each page is supplied by the method getPageTitle(int) in
the adapter supplied to the ViewPager.
I been searching on this on the web, but I didn't get any relevant resources. I just found out another library called actionsherlock that enables the scrolling of tabs without affecting the view which is exactly what I need, instead of using PagerTabStrip's listener .
I'm also searching for the same thing. Too bad you have to make your own implementation or use third-party library. I have read that this library offer the feature of scrolling tab independent of the content. But I have not tried it out yet.
http://viewpagerindicator.com/?utm_source=androidweekly&utm_medium=toolbox
Do you actually mean the ActionBarSherlock? Do you have an example?