This belongs in the development forum. Moving it there now.
Why aren't you using the layout xml?
I'm trying to recreate the GUI from the Notepad tutorial in code instead of XML(I'm not a fan of XML) and I can't seem to get it working, when I debug, I get a vague error message. Can anyone tell me what's wrong with this code? I'm used to java's layout managers and this seems like it should be easy...
Code:LinearLayout.LayoutParams ltp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0); LinearLayout titleContainer = new LinearLayout(this); LinearLayout bodyContainer = new LinearLayout(this); LinearLayout mainContainer = new LinearLayout(this); TextView titleText = new TextView(this); EditText titleEdit = new EditText(this); TextView bodyText = new TextView(this); EditText bodyEdit = new EditText(this); titleText.setText("Title"); titleEdit.setText("Enter Title Here:"); bodyText.setText("Body"); bodyEdit.setText("Enter Body Here:"); titleContainer.setOrientation(LinearLayout.VERTICAL); bodyContainer.setOrientation(LinearLayout.HORIZONTAL); titleContainer.addView(titleText, ltp); titleContainer.addView(titleEdit, ltp); bodyContainer.addView(bodyText, ltp); bodyContainer.addView(bodyEdit, ltp); mainContainer.addView(titleContainer, ltp); mainContainer.addView(bodyContainer, ltp); setContentView(mainContainer);
This belongs in the development forum. Moving it there now.
Why aren't you using the layout xml?
I'm used to the code for of Layouts and I personally like them...
I'm not a fan of XML layouts either. The Google tutorial (and many others) state that you can choose whether to use code based layout or XML based.
But every single book, tutorial or example then goes on to exclusively use XML only layouts, so I would dispute that....
Give the XML layouts a try. There's much more examples and they're actually not that complex once you get your head round them... And the eclipse plugin gives a fairly true representation of what they look like in the preview window.
I tried the code in Eclipse and it worked fine. Can you post the error you are talking about? I have attached 2 screenshots of your code working. I have embedded your code in my own FTP client's TabbedLayout, so just ignore the tabs. But as you can see, the layout is working without error and without modification...
Sorry, I should have posted in the original message what the error was. They are enclosed below.
I can't make much heads or tails of this... I seems like for all intents and purposes it should work.
I don't like XML just because the coding seems easier and nicer to me, but I agree with you that while they say you can do it both ways, XML is the most preferred way of doing it... I guess it's time for this old dog to learn new tricks![]()
Ouch. Those error messages are nasty. Try reinstalling SDK and Eclipse plugin...
Nope. I got it. I had an old reference from something that I neglected to take out. What do those error message usually indicate though, because sometimes In other code I will get it and not know what it's indicating...
Bookmarks