OnClickListener in Android, no errors but application stops -


I do not know why this code is not working. I have TextView named text1 and button called button1 . I want to change the text after clicking text1 in button1 .

I saw that the program works when I line 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;}}}    

Change

setContentView (R) .layout.activity_main);

to

setContentView (R.layout.fragment_main);

Hope that helps ..

OR

As Mike said that copy the entire contents of activity_main.xml from fragment_main.xml ..

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -