Really Blank Activity - android

Firstly thanks to Mark Murphy, regarding comment 10 and the link to a really blank activity template in Android Issue 67513
Now the question regarding the new template: Is it intended that it should still create a new appcompat_v7_n+1 library project?
When I tried it, one was created. I deleted it, removed the reference from the blank activity project, then had to delete references to appcompat styles in the values folders and a style in the manifest.
Don't get me wrong, doing that was no big deal and it's a vast improvement but I'm wondering if that was intended.

Is it intended that it should still create a new appcompat_v7_n+1 library project?
Crap.
The new-project wizard adds some of that. I thought it was all in the new-activity wizard, which also adds some of that when using the stock templates.
I'll need to fork the NewAndroidApplication template to get rid of those bits. I'll work on that. I've added a note to the project README in the interim.
Thanks for pointing this out!

Related

Android Studio changing ID's in one xml file changes the ID's in another file

I used to give simple ids to Android Views, but lately, I stopped that altogether because of this issue.
Let's say I have 2 layouts, one named first_layout.xml and second named second_layout.xml. In each of these layouts, there is a view with id username_input. This id is used in different activity classes to access target view, be it ButterKnife binding, Kotlin Android Extensions, or even findViewById.
Now, for whatever reason, I need to rename id in just one layout. Thus I do Refactor -> Rename. What happens? Android Studio simply replaces id username_input in the whole project, messing other layouts that had view the same id. Most people don't use a unique id for each and every view in the project since it's not mandatory, but I do because I do lots of refactoring, and many times I lost hours because of this non-contextual replacement in the project.
What are my options in this case? Is there a way to make Android Studio do the contextual replacement in such a situation, or should I keep making unique ids in my project?
Moments ago I was facing this same issue and I found it to be the Android Studio's expected behavior, as other elements might be constrained to the element whose ID is getting changed. So you need to update all the IDs particularly in your new layout file through its text editor AND NOT from the Attribute section of its design editor
Its working fine for me, and so must work well for you too :)
I too faced same issue, when i copied widget from an one activity to another activity and tried to change ID in copied widget. It prompt a dialog box and i clicked "No (Local Only)". But, i feel no use of that option. it still updated ID in old activity too.
Workaround:
Try to change ID or Attributes through Code(Text Editor) not from Design.
I feel google should address this issue and remove this bug.
Right click on the id you want to rename the go to:
Refactor -> Rename
Now you will see an option "Scope" and under Scope you need to select "Current File" in order to rename the id in that file only.
(Not sure if it was there when this question was asked!)
I just came across this post because I was having a similar problem. I have an app with different flavors. In one of my layouts I have 12 buttons. In a different flavor, I want all of those buttons plus I add 4 more. So, I created a new version of the layout in a flavor-specific directory. The problem is every time I tried to change anything that has an ID it would change the identically-named layout in the main directory.
With flavors, you're supposed to be able to override the main directory's layout with a flavor specific one. This was extremely frustrating!
This MUST be a bug in Android Studio. The frustrating part is that it's still not fixed. I installed Android Studio via the JetBrains toolbox since I use other JetBrains IDEs. Currently I'm on version 3.5.3
My workaround
To get around this bug I created a "test" project. I copied the layout code that I wanted to modify, pasted it in the test project and edited it there. When I was done altering it the way I wanted, I created the alternative layout in the flavor specific directory (using the same name as the main directory's layout that I want to override) of the actual project I was working on. Then I copied the layout from my test project and pasted it into the flavor specific file. By doing this, it didn't alter the layout in the project's main directory.
My thoughts
You shouldn't have to do this. It's certainly not the intuitive way. This is why I can't believe that this is anything but a bug. With that said, I hope I have provided a clear workaround for anyone else who's stuck. If I haven't comment below and I will clarify what I can.

ActionBarSherlock and appcompat_v7

I have had an old application project that uses ActionBarSherlock. I have found it, and made a few changes to it. Now, I need to add new activities to the project, but when I try to do so, eclipse give me a lot of errors. The reason behind the errors is - I think - that the ActionBarSherlock and appcompat_v7 is interfering with each other as they are using the same resources. So my question is: Is there any way I can add new activities to my project without importing the new support library? (if I add them manually or copy them, they won't be in Manifest.xml)
Thanks in advance.
So my question is: Is there any way I can add new activities to my project without importing the new support library?
Sure. Just don't use the new-activity wizard. Create the Java class the way you would any other Java class. Create the resources the way you would any other resources. Add the <activity> element to the manifest manually. And you're set.

Need explanation on Project Tree Android Studio

I may be missing something here but, how come my android project tree used to look like that when I created my first project 5 months ago (with folders like .idea, build, or R.java)
And now, I've just created a new projet and it looks like that :
Did I make a mistake at some point ? How can I display all the folders and files like R.java ?
Thank you.
If you look at the files outside of Android Studio, you should find that the structure is nearly identical.
What you are seeing is the new Android project view. Note that at the very top of your screenshots the first one says "project" and the second one says "Android."
The Android project view simplifies the way the information is present a bit- for example, it will put all your Gradle scripts together and it will combine drawables with the same name to make finding different versions of the same drawable a bit easier.
If you don't like the new view, you can click on "Android" to see a dropdown containing other options, including the old Project view.
Sorry, silly mistake : the view was different.

Android ActionBarCompat Not working from the start

OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res

Android: How do I create reusable components?

I've spent a while scouring the net for some sort of information on this, but to no avail.
I'm working on an app for which I needed to create some components, some of which would be likely to have other applications, so I'd like to put them in their own package or project, but am not sure what the correct way to do this is.
So my main project is called something like...
<companyname>.<productname>
And I've called the package for my widgets...
<companyname>.widget
I created a separate project for the widgets and moved the relevant code, layout, resources etc over. That project seems to compile properly, but the main project no longer recognises any references to the widgets.
I added the new widget project to the main project's Project References, but that made no difference.
Any ideas or links to tutorial on how to do this correctly would be much appreciated.
Have you tried setting up a library project?
https://developer.android.com/guide/developing/eclipse-adt.html

Categories

Resources