-12

-Edited to clarify duplication-
Start a new android studio project, empty activity. copy the layout default xml to a question. mark it as code. get the error, even though the code seems to be properly formatted. I've read the rules, the advanced help, the "how to post" etc. What is wrong with my question?

"Your post appears to contain code that is not properly formatted as code."

This is the text I'm trying to post:

How to programmatically add ImageView to -ROOT- default layout?
(Without creating a new one)

Explanation : When starting a new project, you get the a default XML.


    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />

    </RelativeLayout>


To create a new ImageView I use

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.somePicture);
    imageView.setLayoutParams(new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT));

Now.. in order to apply it to the Layout, i.e.

    someLayout.addView(imageView);

I need to create that layout, and set it as

    someActivity.setContentView(someLayout);

Problem is - I DO NOT want to create a NEW layout.
In the GUI editor, I can just drag the imageView to the default layout.
So, how can I programmatically access that default layout, and than use the addView on it?

P.S. -
Tried naming the layout and accessing with R.id,
Tried "getWindow().getDecorView().getRootView();"
I really feel like I'm missing something very basic in my understanding, but, what ?

-Original-
I have been trying to post a question for the last 2 hours.
it fails on "code not proper format" msg,
even though i contains no code.
I have tried posting a question on the Meta forum,
but you cannot post if you have less than 5 rep.
in order to get rep, you need to post question.
But as I said - it wont let me post.

How do break the circle?
Who can I ask how to post correctly?

BEFORE YOU LINK ME TO THE SITES RULES
I've read the rules, the advanced help, the "how to post" etc.
My issue is specifically with the editor.

6
  • I didn't know pastebin. Thank you for that. I have already solved the problem, thanks to one of our seniors at work. as expected, it was something stupid. But.. yes. here is the link - pastebin.com/gKNEjvrt. In the original, I've tried the 4 spaces, the <pre> <code> the {} button etc.. nothing seemed to work. THANK YOU !
    – RazVan
    Nov 15, 2018 at 9:23
  • P.S. - thank you for migrating to Meta.
    – RazVan
    Nov 15, 2018 at 9:43
  • 5
    @T.J.Crowder I think there may have been a misunderstanding: the suggestion to use pastebin was so we could see what they were trying to post and figure out why they were having formatting issues, not as an alternative to having their code in the question on main.
    – BSMP
    Nov 15, 2018 at 9:47
  • 1
    @BSMP - Ah, that's cool then, thanks. Nov 15, 2018 at 9:53
  • Right, I can't reproduce this problem. I can paste the code into the question editor, and mark it for code formatting, and it shows up correctly. (Of course, I couldn't post it, since a question can't consist of code only.)
    – legoscia
    Nov 15, 2018 at 10:09
  • "some text of relevance" 2 spaces, enter, copy-paste the xml as-is from a newly created empty android studio, press the "code" {} button. -> Your post appears to contain code that is not properly formatted as code
    – RazVan
    Nov 15, 2018 at 10:11

1 Answer 1

3

Not sure if you already tried this, but starting from the question as you posted in on Pastebin, I had to make two changes to format it properly:

  • The first code snippet started in the first column, so I selected the entire thing and clicked the {} button, to indent it with four spaces and make it appear as a code block.
  • I added an empty line after To create a new ImageView I use - the following piece of code was properly indented, but didn't appear as a code block because it needed an empty line after the previous non-indented line.

After those two changes, the question looked fine to me.

9
  • The moment I select the xml part, and mark it, it gives me the error. To clerify - I've started my selection from the <?xml part, ended at the </RelativeLayout> and deleted everything else, just to make sure.
    – RazVan
    Nov 15, 2018 at 9:57
  • That's really strange, I would expect that error to appear only when you try to post the question. Is it possible to make a screenshot of this problem? Then edit this meta question to add the screenshot and point out the problem.
    – legoscia
    Nov 15, 2018 at 10:00
  • Nope. under 5 rep. cannot use pics in question, cannot comment, answer, vote.. basically cannot do anything except ask and hope. BUT - I've edited the question with simple steps to reproduce
    – RazVan
    Nov 15, 2018 at 10:06
  • Can you post a link to the screenshot? I also cannot duplicate this issue following your steps to reproduce.
    – BSMP
    Nov 15, 2018 at 10:45
  • 1
    Now I cant reproduce either. Did the exact same thing 5 times. It err on me twice, and than stopped. So frustrated... could it has something to do with refresh, or.. I'm head on dumbstruck.
    – RazVan
    Nov 15, 2018 at 11:55
  • Did you have any other weird javascript issues at the time?
    – BSMP
    Nov 15, 2018 at 12:10
  • Not that I've noticed. just that one. I've tried to post my original question again, and it errors again. paste.pics/d6ee9fff88fc8ebe85f0119befe231f6
    – RazVan
    Nov 15, 2018 at 12:44
  • @RazVan I edited your question to include the screenshot, and voted to reopen it, as it appears that the duplicate questions don't answer what's going on here.
    – legoscia
    Nov 15, 2018 at 12:51
  • 2
    If I could, I would vote to close this. After a few more hours of playing with it, it's probably some end line char, or something similar that passes on the copy-paste, or a tab, or.. something similar.Thanks for trying though.
    – RazVan
    Nov 15, 2018 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .