textview - issue with my first android app -
before posting question , wanna clarify first post on stackoverflow , let's story beggin.
as title said , i'm making first app on android , found myself blocked issue .
there 3 button on app : button1 : give textview2 "hello world again " , make visible // button2 : make textview2 invisible // button3 : make textview1 invisible
this code freom main_activity :
package com.example.ismail.app_test_1; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class mainactivity extends actionbaractivity { button button_aff; button button_hide; button button_hide_hw; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button_aff = (button) findviewbyid(r.id.button); button_hide = (button) findviewbyid(r.id.button2); button_hide_hw = (button) findviewbyid(r.id.button3); button_aff.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { show("hello world again"); } }); button_hide.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { hide(); } }); button_hide_hw.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { hide_hw(); } }); } public void show(string str) { textview text; text = (textview) findviewbyid(r.id.textview2); text.setvisibility(view.visible); text.settext(str); setcontentview(text); } public void hide() { textview text; text = (textview) findviewbyid(r.id.textview2); text.setvisibility(view.invisible); setcontentview(text); } public void hide_hw() { textview text; text = (textview) findviewbyid(r.id.textview); text.setvisibility(view.invisible); setcontentview(text); } }
after getting on phone , when touch button : "unfortunatly,app_test_1 has stopped ! can me ?
edit : removed setcontentview , works , lot guys. if has tuto me improve android programming skills i'm taker
do not use setcontentview()
method outside of oncreate()
delete in show , hide functions. should work probably
Comments
Post a Comment