Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my solution for my special Problem.</p> <p>In case the username wouldn't be found in the db i had to create a RelativeLayout that looks like the xml-generated one.</p> <pre><code>// text view appears on top of the edit text enterNameRequest = new TextView(mainActivity.getApplicationContext()); // fill the view with a string from strings.xml enterNameRequest.setText(mainActivity.getResources().getString(R.string.enterNameRequest)); // edit text appears below text view and above button enterName = new EditText(mainActivity.getApplicationContext()); enterName.setId(667); // button appears at the bottom of the relative layout saveUserName = new Button(mainActivity.getApplicationContext()); saveUserName.setText(mainActivity.getResources().getString(R.string.useUserName)); saveUserName.setId(666); // generate the relative layout RelativeLayout layout = new RelativeLayout(mainActivity.getApplicationContext()); layout.setId(668); // set a background graphic by its id layout.setBackgroundDrawable(mainActivity.getApplicationContext().getResources().getDrawable(R.drawable.background_head_neutral)); // runtime told me that i MUST use width and height parameters! LayoutParams params2 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params2.addRule(RelativeLayout.ABOVE, 666); enterName.setLayoutParams(params2); LayoutParams params3 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params3.addRule(RelativeLayout.ABOVE, 667); enterNameRequest.setLayoutParams(params3); LayoutParams params4 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params4.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 668); saveUserName.setLayoutParams(params4); // add views layout.addView(enterNameRequest); layout.addView(enterName); layout.addView(saveUserName); /* todo: set button action */ mainActivity.setContentView(layout); </code></pre> <p>What i found out additionally: It is not so good to manipulate the layout manually from within java!</p> <p>You should better use a new Activity and set a new layout in it.</p> <p>This way, the application-code is readable a lot better!</p> <p>I even tried to set several layouts (not manually, but wit setContentView) in one activity, and it turned out that i didn't know where what was accessing what else... Also, i had a great problem in adding onClickListeners... so you better use -- android:onClick="myButtonMethod" -- in your button tag in the xml and have a method in your according activity, which uses the layout, like this:</p> <pre><code>public void myButtonMethod(View v){ // do stuff } </code></pre> <p>This improves performance because you are not using additional Listeners - but you use the already available Listener that is bound to your activity in every case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload