After port to AS, adding a button

Hi,
I have ported my Proc4A app to AS. The App works “full screen”, I guess what’s called “match parent”. The App only draws Graphics elements in there. The related XML file, which was created by AS during the importation is:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment"
    android:name=".MiniEFIS"
    tools:layout="@layout/fragment_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

I would like now to create 2 buttons in the area, where nothing is drawn yet, and later use something like mouse over or pressed to increment/decrement a local variable in my code.
If I try to drag a button into the frame area, using the AS drag&Drop design tool, but I cannot place the button; hence apparently this is not allowed.
How to?
Thanks for helping
hk

@lve0200 ===
you have to add your buttons by code; the xml you have put is the “general” fragment created by p5 which creates also a frameLayout (by code) and adds also by code the applet to the fragment and the fragment to the frameLayout. As for more details look inside this forum or the previous one, i have put code for that. Guide line: onStart() you get the frameLayout, you create your buttons and give attributes to them (x, y, background…) - then (but it can be inside a runnable, depends if your buttons change) you have to add them to the view, that’s all.

Hi,
tried hard in both Forums, but couldn’t find the right 1 among 1000s.

I guess you mean this:

public class MainActivity extends AppCompatActivity {
  private PApplet sketch;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(CompatUtils.getUniqueViewId());
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
                                                     ViewGroup.LayoutParams.MATCH_PARENT));
    
    sketch = new MiniEFIS();
    new Thread(new listen()).start();
    PFragment fragment = new PFragment(sketch);
    fragment.setView(frame, this);

Could you give me a hint, where to find this code snippet, you’ve been talking about? I’ll try to adopt it, if I can see it.
Rgds
hk

@lve0200 ===

Yes, that is exactly what i have described; as for the second question sorry, as for now i am working and cannot get time to look at that, but the principle is always the same (except for some kind of views, like texture or surface): you get the framelayout and add to it (with the addView() method from android ) your buttons or textView or imageView and so on.

I’m stuck! Its not urgent, hence leave yourself time, but eventually I could use some help.
I tried this:

public class MainActivity extends AppCompatActivity {
  private PApplet sketch;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(CompatUtils.getUniqueViewId());
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
                                                     ViewGroup.LayoutParams.MATCH_PARENT));
    
    sketch = new MiniEFIS();
    new Thread(new listen()).start();
    PFragment fragment = new PFragment(sketch);
    fragment.setView(frame, this);
    
    Button newButton = new Button(this);
    newButton.setText("Hello");
    fragment.addView(newButton);
  }

but in the last line addView cannot be solved.
Rgds
hk

 Button newButton = new Button(this);
    newButton.setText("Hello");
    frame.addView(newButton);

compiles OK, but no button.
really trying hard. All explanations I can find in INET are with (R.layout.activity_main);

Hi,
sorry to bother,
its working. The button just got overpainted by the draw() function.
Thanks anyway.
hk