Facebook
From Innocent Lechwe, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 71
  1. package vistula.ml.projekt2;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.constraintlayout.widget.ConstraintLayout;
  5. import androidx.constraintlayout.widget.ConstraintSet;
  6.  
  7. import android.content.Context;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.  
  21.         ConstraintLayout constraintLayout = findViewById(R.id.constrainedLayout);
  22.         ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT);
  23.  
  24.         Button button3 = new Button(this);
  25.         button3.setText("Button3");
  26.         button3.setId(View.generateViewId());
  27.         button3.setLayoutParams(params);
  28.         constraintLayout.addView(button3);
  29.         int x3 = 190, y3 = 700;
  30.         ConstraintSet set = new ConstraintSet();
  31.         set.clone(constraintLayout);
  32.         set.connect(button3.getId(), ConstraintSet.LEFT, constraintLayout.getId(), ConstraintSet.LEFT, x3);
  33.         set.connect(button3.getId(), ConstraintSet.TOP, constraintLayout.getId(), ConstraintSet.TOP, y3);
  34.         set.applyTo(constraintLayout);
  35.  
  36.         button3.setOnClickListener(new View.OnClickListener(){
  37.             @Override
  38.             public void onClick(View v){
  39.                 rewriteMyInput(v);
  40.             }
  41.         });
  42.  
  43.         ConstraintLayout.LayoutParams params1 = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT);
  44.  
  45.         Button button4 = new Button(this);
  46.         button4.setText("Button4");
  47.         button4.setId(View.generateViewId());
  48.         button4.setLayoutParams(params1);
  49.         constraintLayout.addView(button4);
  50.         int x4 = 650, y4 = 700;
  51.         ConstraintSet set1 = new ConstraintSet();
  52.         set1.clone(constraintLayout);
  53.         set1.connect(button4.getId(), ConstraintSet.LEFT, constraintLayout.getId(), ConstraintSet.LEFT, x4);
  54.         set1.connect(button4.getId(), ConstraintSet.TOP, constraintLayout.getId(), ConstraintSet.TOP, y4);
  55.         set1.applyTo(constraintLayout);
  56.  
  57.         button4.setOnClickListener(new View.OnClickListener(){
  58.             @Override
  59.             public void onClick(View v){
  60.                 rewriteMyInput(v);
  61.             }
  62.         });
  63.     }
  64.  
  65.     public void rewriteMyInput(View view){
  66.         EditText myEditText = (EditText)findViewById(R.id.editText);
  67.         String myText = myEditText.getText().toString();
  68.         TextView myTextView = (TextView)findViewById(R.id.textView);
  69.         myTextView.setText(myText);
  70.     }
  71.  
  72.  
  73. }