source classes for android views - java

It is kind of a general question but I noticed that I needed it multiple times and could not find an answer.
There are many cases where I needed to change a view to make it work for my specific purposes and I needed to create a custom TextView, custom EditText, custom autoCompleteTextView and so on.
Where can I find those source codes so I could use them and change them for my purposes?
Thank you

You can create new class extend from TextView or EditText and do it.
To find source codes you can with ctrl+U on class.

Related

How to update content of the activity without creating new Activity?

I'm trying to make an app and I have made a blueprint for a specific activity, but I don't know how to implement it. The layout contains few buttons at the top of the activity, and each button features some information, which is displayed inside the view. The view which needs to be updated is present under the buttons. I don't want the activity to be changed, instead it should update the contents of the View, which is different for each category/button.
By doing some research I have realised that the "Tab Layout" can be used to achieve my requirements, but I don't want the tabs and I need some stylish buttons as a replacement.
I know I'm not the best at describing, so I have looked upon Dribble and found one design which is 100% similar to blueprint.
I want to achieve this using XML and Java using Android Studio! Every suggestion will be a great support foy my app.
Thanks a lot.
As far as I know, you could achieve that by using fragments (which is the same concept you would have used on TabLayout). I don't really know how much knowleadge you have on Android, but if you know what a Fragment is, it should be easy for you to recreate the idea.
You have 3 buttons for 3 different fragments, so you must design every fragment by separate and change it depending the button you click.

Flexible Space With Image With ViewPager Tab Activity

i want to implement FlexibleSpaceWithImageWithViewPagerTabActivity.java in my application. i mean i want to achieve behavior that is shown by this above class. It shows flexible space with image and viewpager with tabs, and has smooth scroll of actionbar with recyclerView.
Here is the code of this class.
i am trying to implement this class. Anybody please help me, how can i use this class or can make my own class having similar behavior.
i have imported this class from this library using gradle. But don't know how to use it.
Thanks in Advance

How to Determine XML layout for Fragments in Tabs?

Okay, So I just started Android development (I am average at VB.Net, so I understand basic code even if its not in VB). I've made a couple play around apps which used Text-To-Speech, Async Tasks and Reading/Writing files. However, I now wish to make a tabbed Android app.
I started the project in Eclipse Juno and filled in all the details. I then selected (For navigation) the Tabs/Swipe layout. I now have the default code for that layout type (Link to Tabs on developer.android.com - http://developer.android.com/design/building-blocks/tabs.html).
I understand mostly what the default code is doing. The only problem I am having, is determining the individual layout of my Tabs. I wish to have 2 Tabs, 1 in which the user selects an option, and the other, in which an image is shown depending on the selection in Tab 1.
So the question is: How do I create a .xml file in Layout to determine what is shown on the Fragment?
If you want to do this in XML the answer is simple, it can't be done just with XML, you must create a class that's implementing a ActionBar.TabListener.
Than you can override the onTabSelected method in which you can exchange the content.
A proper solution would be:
Use a LinearLayout as root container, and implement two Fragments for each of your Tabs (there you can design an individual XML-layout). Now you can add one fragment initially to the root-container and implement the exchange of the layouts inside the onTabSelected method and you are done.

ViewStub - Show view with dynamic content

This may be a dumb question, so my apologies if so; I'm fairly new to Android.
But anyway - I have a working ViewStub, which is replaced by different layouts depending different situations. It's working fine with regards to showing the correct layout when I call the setLayoutResource() method, and then setVisibility to VISIBLE. However, I now need some of the content in this view that is being shows to be dynamic (i.e. I need to set it via code rather than just show a static layout).
Is this even possible? The setLayoutResource() method only takes a static layout-resource ID, but I need that layout XML file to be able to have it's TextViews contain non-static text that comes from some code that I have ready to utilize. How should this be approached if possible? I understand the concept of having a Java class, and inflating the XML to attach itself to it to update the fields, but I can't see how that relates to my code at hand, since it's simply a layout resource int I need to set for the setLayoutResource() method in ViewStub.
I can post existing code if needed, but I'm not sure it do much more than clutter up the post. For reference - All I have is a simple layout XML file with some TextViews, and then my main XML containing the ViewStub, which is part of a custom Dialog. The user is able to instantiate the Dialog and set the layout, which in turn sets the layout of the ViewStub. This is the layout in which I need the dynamic content to be used.
Any advice would be greatly appreciated. Thanks!
Turns out this wasn't too difficult to accomplish. I just needed to use the ID of the TextView layouts after inflating the ViewStub to get a copy of the actual TextViews, then I was easily able to set their text to whatever kind of dynamic/custom text I desired.
I also needed to comment out the code that shows it via the .VISIBLE call, and instead do the following (the .inflate() line of code accomplishes the same thing as setting it to VISIBLE):
View inflatedView = dialog.myStubView.inflate();
TextView myTextView = (TextView) inflatedView.findViewById(R.id.my_text_view);
myTextView.setText("Dynamic/Custom Text");

android default xml layout not loading

I'm trying to make a ListActivity with check boxes using one of the built in android layouts, android.R.layout.simple_list_item_multiple_choice. For background, I'm fetching the list in a private AsyncTask, then calling the adapter like this:
listActivity.setListAdapter(new ArrayAdapter<String>(listActivity,
android.R.layout.simple_list_item_multiple_choice, mDisplayList));
However when I run my code, the ListView is displayed with list_item.xml, which I'm using for all the other ListViews in my project. Any idea why this is happening?
The reason the right xml layout wasn't being used was because my AsyncTask was extending my (other) custom AsyncTask that used another xml layout and I left in this line.
super.onPostExecute();
which was at the end of the method so the inherited layout trumped the one I wanted.
When you use the android R in this way: android.R.layout... than you already have the package android before the class name R.
If you explicitly provide a class name with a complete package name, you don't need to import it, too.
That's for the case that you have the same class name from different packages which happens often when you use the android.R and your generated R class.
You don't need to import android.R.layout since you invoke it explicitely using android.R.layout.simple_list_item_multiple_choice.
That post may be of use.
Update from comment
It's hard to figure out what's the problem. Did you try to clean your project and rebuild? Sometime android int id's just do strange things if you don't clean the project and regenerate the gen files. But messing android internal references is highly unlikely… If it doesn't work, you may have another polluting setListAdapter somewhere else but it's hard to say without your full project.

Categories