Hello
on youtube I find tutor how create program with android studio. Tutor show me how create first activity and put one edittext and tree buttons, first and second button write in edittext which button I pressed.im add
On first activity I have edit box and third button show me second Activity. This works normal. Click on button on first Activity show me second Activity
I make second activity with one edittext and tree buttons,.and copy some code from first Activity. Code must show me which button I click but dont work. Where's mistake?
// Start code first activity package com.pingusteam.mybigapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class FIRST extends AppCompatActivity { public Button but1; public Button gumb1; public TextView vnos; public Button izpis; public TextView prikaz; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); final Button but1 = findViewById(R.id.but1); final Button gumb1 = findViewById(R.id.gumb1); final Button izpis = findViewById(R.id.izpis); final TextView vnos = findViewById(R.id.vnos); final TextView prikaz = findViewById(R.id.prikaz); gumb1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setContentView(R.layout.activity_second); } }); but1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //setContentView(R.layout.activity_tretji); prikaz.setText("to je črka B"); } }); izpis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { prikaz.setText("to je črka A"); } }); } }
// Start code second activity package com.pingusteam.mybigapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class second extends AppCompatActivity { public Button gumba; public Button gumbb; public Button gumbc; public TextView pozdravtxt; public TextView prikaz; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); final TextView pozdravtxt = findViewById(R.id.pozdravtxt); final Button gumba = findViewById(R.id.gumba); final Button gumbb = findViewById(R.id.gumbb); final Button gumbc = findViewById(R.id.gumbc); gumba.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { pozdravtxt.setText("Pritisnili ste črko A"); } }); gumbb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { pozdravtxt.setText("Pritisnili ste črko B"); } }); gumbc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { pozdravtxt.setText("Pritisnili ste črko C"); } }); } }