OnClickListener in Android, no errors but application stops -
I do not know why this code is not working. I have I saw that the program works when I line Change to Hope that helps .. OR As Mike said that TextView named
text1 and
button called
button1 . I want to change the text after clicking
text1 in
button1 .
button1.setOnClickListener (this); But nothing happened as a result.
package com.example.testowaniefragmentow; Importroid.os.Bundle; Import android.support.v4.app.Fragment; Import android.support.v7.app.ActionBarActivity; Import android.view.LayoutInflater; Import android.view.View; Import android.view.View.OnClickListener; Import android.view.ViewGroup; Import android.widget.Button; Import android.widget.TextView; Public Class MainActivity ActionBarActivity implements OnClickListener {TextView text1; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Button Button 1 = (Button) Find VVBIID (RID button 191); button1.setOnClickListener (this); TextView text1 = (TextView) findViewById (R.id.textview_text); If (saved instenstat == empty) {getSupportFragmentManager () StartTransaction () Add (RID Container, New Placeholder Fragment ()). Commit (); }} Public static class extends the placeholder fragment {public placeholder fragment (} {} @ override public view crate view (LayoutEfterter Inflator, View Group container, bundle saved instanestate) {see Routview = Inflation Inflate (R.Left.Frenchment_man, Container, Falls); Return Root View;}} @ Override Public Zero (click V) {Switch (v.getId ()} {Case R.id.but ton_B1: text1.setText ("text has been replaced"); break; default: brake;}}}
setContentView (R) .layout.activity_main);
setContentView (R.layout.fragment_main);
copy the entire contents of activity_main.xml from fragment_main.xml ..
Comments
Post a Comment