I am learning Android and want to be able to add line comments to my XML so I can remind myself what things are doing.
Is there an accepted practice for this, or is it possible in Android Studio? I recall reading that comments in XML are hard, so I wanted to know if that was also considered true here.
As mentioned above you can comment in XML just like this:
<!-- Comment -->
But in android studio you can very easily toggle comment just by selecting what you want to comment and then pressing:
CTRL + /
This not only for XML but also for your java code for example.
It is indeed possible. I'm not sure if there is an accepted practice, but you can accomplish leaving a comment like this
<!-- comment goes here -->
Same as in all XML applications:
Just use <!-- ... --> to comment.
Comments in XML aren't too tough. You have to do it like this:
For example
<!-- This is a comment -->
Please don't hesitate to ask for anymore help. The above should work in android studio.
If you are using a Mac then command is command(button which looks like Windows start button ) + /
If you are on Windows then it is
Cntrl + /
Try and see if it works
In Android Studio DOLPHIN version I have tried using the
and the file does NOT like it. It produces errors when used.
I don't know about XML files much, but this AndroidManifest.xml file does not like this. Any other tips that might work? This file is error free before the comment line is added.
Related
In the new android studio 3.3 or 3.2 if we create a for example button auto generate create a text like
<Button android:layout_width="" android:layout_height=""/>
but I would like something more like this
<Button
android:layout_width=""
android:layout_height=""/>
like old versions of Android studio is there a setting or something for that?
That is related to XML code wrapping. By default it should be on wrap always but maybe it's not in your Android Studio or they changed that in newer versions. Anyway you can find that by click on:
Preferences -> Code Style (expand it) -> XML -> Android(Tab) ->
Here you can find Layout Files and below options like: Wrap always, Don't wrap, Wrap if long etc. So set it on Wrap always and Apply changes and your XML code from now on should be wrapped.
It hints something that says reduce intent with 4 spaces. Try to configure that :)
Or use the hard way by pressing enter for the new row.
There are similar questions, but none address my specific issue.
I'm rather new to Android development and Eclipse but was able to follow the tutorials A OK.
In fact, I'm able to edit activity_main.xml from a tutorial, but now, in a test project I'm working on, I can't edit my new activity_main.xml (again, different project, same filename).
I created the file by right-clicking on the layout folder then selecting NEW > OTHER > Android XML Layout File. I was able to copy some of the other file so that my file now looks essentially like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
When I type, the cursor moves around (looping through the text) but no characters appear on the screen. Again, in the other XML file I can edit with no problem.
I'm hoping that this is just some newbie problem.
I have had similar problems, though not this exact problem. Sometimes simply restarting Eclipse, or whatever editor you use, can help. Occasionally, Eclipse will not detect changes in your xml so you need to clean and rebuild the project. You can do this by
Winodow --> Project --> Clean...
and choose your project
I know there was an issue that I had which was similar with the editor jumping/replacing lines and such which I believe was fixed in a newer version of Eclipse. If I can find a source later I will edit
Clear all of text in layout activity_main.xml (in code view)
Drag and drop new LinearLayout in layout (in graphical view)
Go to Project -> Clean
I am using this library from Chris Banes (I will never thank this man enough). It has two different behaviors depending on the android version. I want to get rid of the graphical hint on the PullToRefresListView (circled in the image below) that is shown only on devices with android lower than 4.0.
Does anybody knows how to do it?
SOLUTION:
for anybody in the future searching for the same solution here it is: in the PullToRefreshAdapterViewBase class change getShowIndicatorInternal method from this:
private boolean getShowIndicatorInternal() {
return mShowIndicator && isPullToRefreshEnabled();
}
to this:
private boolean getShowIndicatorInternal() {
return false;
}
If you use a layout XML file, you can also specify ptr:ptrShowIndicator="false" inside the PullToRefreshView's declaration. For example:
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/pullToRefreshListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
ptr:ptrShowIndicator="false" >
</com.handmark.pulltorefresh.library.PullToRefreshListView>
For other attributes, you can refer to /res/values/attrs.xml in the library, which is self-documented.
You may also find the sample project worth looking at.
Quick and dirty- Simply replace the image file for arrow hint with a transparent image in res folder of library.
I'd say try to see if you can adjust the code to simply take it out.
I don't know if there are any methods added to do this for you, but if there are they should be easy to find.
Scrolling through the code a bit quickly, this might be something;
https://github.com/chrisbanes/Android-PullToRefresh/blob/master/library/src/com/handmark/pulltorefresh/library/internal/IndicatorLayout.java
Although i'm not sure if this is actually that arrow, since it doesn't show any hints in this class about being version-based.
I need to set a button's text to just ?.
I'm happy to do it via Java, but would rather do it via the XML.
Is it possible?
I've tried android:text="?" and android:text="?" but it did not work.
Then I set one of the string resources to ?, and when that did not work I set it to ?referenced that but it doesn't work!
How do I set the button caption to ? using XML?
You need to escape the question mark...
android:text="\?"
Write "\?" Intead normal or ASCII form.
You try this way.. just give space before or after ? this will work i think..
android:text=" ?" or android:text="? "
give the space before writing the ?(android:text=" ?")...it's working fine.other wise. you have to add image to button(android:background="#drawable/image"). or u need to take imagebutton add question mark image to it.
Part of your problem is that in some versions of the Eclipse Android Layout Editor, it will freak out with a question mark as its text on a button. I submitted a bug report, and after a year I received a note saying that the bug is fixed.
So make sure you have version 21.1 or greater of the API to get the bug fix.
See my question about this: Android Layout Editor Freaks Out on Question Mark
Hope this helps.
Try using a \ before the question mark like this "\?".
Eclipse give me a good experience in code assistence.But when it comes to animation xml files and i enter alt+/,it pop up nothing.So it make me very easy to type a wrong attribute name because of my poor english.can you give me a hand?
thanks.
Make sure that your animation xml file is location in anim folder not animation folder
I am not sure what you mean by "animation xml file" (the CEGUI ones? Android ones?), but, as explained in "eclipse editor, ex: xml editor, code assistance. how it works?", any xml file with auto-completion needs a DTD or Schema informtion.
Sometime, the DOCTYPE at the beginning of the xml file can prevent the auto-completion to work.