Been working on an android application with a custom listview. I recently had to change to a cursor to accomplish what I wanted to do.
As a result, I ended up making use of android.R.layout.simple_list_item_2 because it worked how I wanted. Problem is that I would like to change a few properties such as font color and edit my cell as I see fit.
Question is, Can I find the code for simple_list_item_2 somewhere and edit it as my own, and call it instead of simple_list_item_2?
easy to get it. If you use Android Studio, you can put your cursor on android.R.layout.simple_list_item_2 and press Ctrl + B or F4 to get it.
if I don't make a mistake, F4 similar to F3 on Eclipse!
UPDATE 1
on Android Studio, you also get it by right click on it and Go To >> Declaration
UPDATE 2
on Android Studio, you also get it by hold controll and click on simple_list_item_2.
If you use Android Studio on MacOS, let hold CMD instead
You can find the code for this component by searching for simple_list_item_2.xml in the Android Open Source Project's frameworks. For example, it's available here in the GitHub mirror of the official repository.
Related
VSCode have a great option what helps developer to make code more beautiful. I mentioned in the given picture. It indicates each brackets related to which case. I've worked on flutter in VSCode but now I've decided to work on Android Studio for some reasons and unfortunately I don't know where I can find it. Did you guys know how I can fix it?
I have to apologize for Title because I don't know what this option is?
You can also use following command to make more beautiful and easy
(1) Search Everywhere (Press Shift Twice / Press Shift Twice)
(2) Recently Opened Files (CTRL+E/Command+E)
(3) Find Action (CTRL+Shift+A/Command+Shift+A)
(4) Generate Code (ALT+INS/Command+N)
(5) Override Methods(CTRL+O/Command+O)
(6) Delete Line at Caret/Cursor (CTRL+Y/Command+Y)
(7) Collapse/Expand Code Blocks (CTRL+- / Command+-)
(8) Collapse/Expand Whole activity code (CTRL ALT - /CTRL ALT +)
(9) Reformat Code (CTRL+ALT+L / Command+Option+L)
Just Press CTRL+ALT+L on Windows or Command+Option+L on Mac. The android studio will reformat all the code for you. And the good part is that it works for XML layouts as well.
Use CTRL+ALT+L to reformat your code.
Use CTRL+ALT+O to optimize imports.
Use CTRL+ space to complete code.
When editing Java files, if I'm at the end of the line and I type the Enter key, it starts the next line properly indented 4 columns, to match the line above. That's OK but it's indenting with a tab, not spaces, even though in File>Settings>Editor>Java>Tabs and Indents the checkbox for Use tab character is unchecked, and always has been.
If I just type the tab key I also get a tab, not spaces.
I never want to use tab characters; I always want to use spaces. I don't have this problem in Eclipse or Microsoft Visual Studio so it's not some system setting for my PC. Is there some other setting in Android Studio for this?
Edit: I tried the suggestion that Omar Al Halabi (below) made and it didn't work but while testing it I noticed something interesting: This tab problem seems to mainly apply to the beginning of the line, i.e., if I type Enter on the previous line, it immediately tabs over to the first indent position on the following line, using real tabs, not spaces. On the other hand if I'm typing some text on an existing line, once I've typed a little text, if I hit tab, it then tabs over using spaces.
hope this helps,
check Use Tab Character,
give all that values to zero than you not get space on enter in java code, like in below image,
one more thing is you have to change your code format settings or may need to disable it
This is not an answer, but I don't have enough reputation points to post my questions as a comment.
- Is this issue happening in all your Android Studio projects?
- Are you using the Default scheme for the general File->Settings->Editor->Code Style and also for the Java Code Style?
- Have you tried making a new Java Code Style scheme at the Project level for just one project as a test?
EDIT: This is a brute-force/shotgun approach.
Rename your \Users\<username>\.AndroidStudio2.1 directory (e.g., .AndroidStudio2.1_orig)
Open Android Studio and force it to use the default settings by choosing the "I do not have a previous version of Studio or I do not want to import my settings" option when the "Complete Installation" dialog window appears.
Run a recursive 'diff' between the new and old .AndroidStudio2.1 directories to find any changes you've made to the default settings so you can re-apply them. The settings are kept in XML files so they are human-readable. Keep an eye out for any differences that may affect Android Studio use of tabs & spaces, because those might be the source of the problem.
If this does not work, then you may have to re-install Android Studio.
Try opening Settings->Editor->Code Style->Java. Check "Use tab character". Click OK.
Then go to File->Invalidate Caches\Restart -> Invalidate and Restart.
Then, again, go to Settings->Editor->Code Style->Java. Now uncheck "Use tab character" and hit OK.
If it still doesn't work change tab size and indent and then restore them back if you want.
The IDE tries to position the lines as if they belong to the same block. Also very likely you had used the tabs on the previous line. You can try to deactivate Detect and use Existing file indents for editing
I've created a Live Template under the "user" template group. I've set the Abbreviation to "setpref". It is listed on my list of Live Templates, but it is not available when I type "setpref" in a code window. I'm guessing that I've missed something obvious but can't work out what.
Any ideas??
To make the Live Templates appear again, do the following:
1) Open Editor>Live Templates
2) When you find templates with issues, select them and do step 4-6
3) At the bottom, click Change where it says "Applicable in..."
4) In the popup, under Java select statement to make templates like logd, logm, logw etc be available inside methods.
5) Select declaration to make templates like logt available in classes' field declarations.
Done!
Visit this link - https://www.reddit.com/r/androiddev/comments/3n9nis/issues_with_live_templates_in_android_studio_try/?st=j0pjkc4w&sh=e84eb254
Have fun ! :) It works.
Please make sure that you've correctly specified the context for your live template (the set of languages in which it's available).
If you see below the editor of live templates this sentence.
No applicable contexts.
click on "Define" beside the text.
select the language you coding.
Ok.
If you are using Kotlin:
Open the "Preferences" menu item
Search "Live Templates"
Put your template below Kotlin set
I am trying to extract style in android studio 0.8.9 using the refactor option. But it seems to be disabled for some reason. I have tried cleaning and rebuilding the project just in case and even restarting Android Studio, but nothing seems to enable the extract style option.
Do let me know if anybody else is facing the same problem or is there a way to solve this ?
Screenshot image:
I had the same problem. Extracting styles is different in Android Studio:
You don't need to select text and choose Refactor->Extract->Style, just choose the menu option With no text selected.
So, just click anywhere inside the ImageView element (Do not select any text). The refactor option should become available.
Works fine for me without selecting any code. To extract layout you need to select the whole layout not just a part of it.
I thought ADT should come with a visual editor for building GUI : Easy way to build Android UI?
However, I just cannot find it. I was wondering where is the Visual Editor for Eclipse with the ADT plugin.
I can run HelloWorld application without problem. However, whenever I click on main.xml at the left navigation tree layout folder, here is what I get. What I wish to get is a WYSIWYG editor.
Select your main.xml file. At the bottom of eclipse you can see a Layout tab, click on it and eclipse will open the android gui editor.
As Paul Kearny previously noted, to resolve issue with seeing "Design" tab instead of "Graphical Layout" follow these 2 steps:
1) Delete project from the left of the screen, without deleting the source files
2) File -> Import -> Existing Projects into Workspace, browse and select your workspace folder and open your project
Graphical Layout problem fixed!
If you want to edit the layout visually, rather than through XML, click on the Layout tab at the bottom left of the main.xml window (in your screenshot, just above Problems).
Also note, there are issues with displaying some of the widgets. For example, the ListView does not render. So, my hint is to change ListView to just a View, then work out the details of the layout so you can get the colors, relative-ness, etc. Then switch it back to ListView. There is one other widget that I cannot recall off the top of my head ...
To resolve issue with seeing "Design" tab instead of "Layout" or "Graphic Layout", I had to:
1. Delete the project from Eclipse without deleting the source
2. Shut down and restart Eclipse
3. Import the project back in
You could probably skip step 2, but I did it just to make sure.
Hope this helps anyone else who has the same issue.
If your view is showing Design|Source for the .xml file right click on the main.xml and select open with - android common XML editor. Simple.
If it is happening to one particular xml, you can delete the file (make sure you copy the content first), create new xml and paste the content again.
I recommend that any serious Android developer stay far, far away from Eclipse/ADT Design View. This is a time-wasting tool that sorely lacks the attention it would need from Google to make it worth serious consideration. It doesn't render the views as a real device would. There is no way to bind dynamic data. Does it work with fragments (I think not)? For it to work properly and have useful features would weigh down Eclipse further and make it unacceptably slow. In my very humble opinion, the entire strategy for ADT's ui-design tools has failed.
Thus, the recommendation is: edit Android XML layout files by hand and use the only reliable testing mechanism you have for layouts: actual devices. You can always fallback on the emulator - but the emulator performs 50x - 100x slower than an actual device. I'm not exaggerating. Pick your poison!
new fix, took me forever to get this fixed, really simple....delete the xml file and undo the deletion (ctrl+z), double click and there you go. Hope this helps someone as it did me. No shut down required.
If you see "Design" tab instead of "Graphical layout", just close the project and open it again.