Note that there are some explanatory texts on larger screens.

plurals
  1. POonClickListener not working after setContentView
    primarykey
    data
    text
    <p>MainActivity</p> <pre><code>package com.Kevious.Kevin; import android.app.*; import android.os.*; import android.view.*; import android.widget.*; import android.view.View.*; import android.opengl.*; import android.content.*; import android.text.*; import java.net.*; public class MainActivity extends Activity { String passw; String value = "Test"; int i = 1; TextView textView; Button button; EditText editText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.textView); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View p1) { loadMethod(); } } ); editText = (EditText) findViewById(R.id.editText); editText.addTextChangedListener(new TextWatcher(){ public void beforeTextChanged(CharSequence p1, int p2, int p3, int p4) { } public void onTextChanged(CharSequence p1, int p2, int p3, int p4) { // TODO: Implement this method passw = editText.getText().toString(); textView.setText(passw); passw = textView.getText().toString(); } public void afterTextChanged(Editable p1) { } } ); } public void loadMethod() { passwCheck(); } public void passwCheck(){ passw = textView.getText().toString(); if (passw.equals("kev")) { Toast.makeText(this, "corrrect " + passw, Toast.LENGTH_SHORT).show(); setContentView(R.layout.nextactivity); } else { Toast.makeText(this, "incorrect " + passw, Toast.LENGTH_SHORT).show(); } } } </code></pre> <p>NextActivity</p> <pre><code>package com.Kevious.Kevin; import android.os.*; import android.content.*; import android.app.*; import android.widget.*; import android.view.View.*; import android.view.*; public class NextActivity extends Activity { Button button2; TextView textView2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); textView2 = (TextView) findViewById(R.id.textView2); textView2.setText("Welcome Kevin"); button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new OnClickListener(){ public void onClick(View p1) { textView2.setText("button clicked"); buttonclick2(); } } ); } public void buttonclick2(){ Toast.makeText(this, "logged out", Toast.LENGTH_SHORT).show(); setContentView(R.layout.main); } } </code></pre> <p>Im new to stackoverflow, so I hope I am creating this correctly. I apologize if I did it wrong.</p> <p>I am learning Android Development and just experimenting and creating my first app and somehow I encountered a problem where one of my buttons do not work, even when I have added the button listeners correctly.</p> <p>When I type "kev" as the password on the main layout and press the button, it will take me to NextActivity Layout via the "setContentView(.....)" this works fine.</p> <p>The problem is, when I am in the NextActivity Screen, it will have a button. Somehow when I click on that button, it does nothing. I am sure the code is right. Can someone help me out here?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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