java - The method findViewById(int) is undefined for the type R.layout -



java - The method findViewById(int) is undefined for the type R.layout -

i started programming android recently, , have problem. i'm trying word written in edittext, string.

package com.example.generatoredifrasi; import android.os.bundle; import android.r.layout; import android.os.bundle; public class edittext { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_layout); edittext text = (edittext) findviewbyid(r.id.edittext); string string = text.gettext().tostring(); // value edittext } }

findviewbyid gives me error: the method findviewbyid (int) undefined type r.layout

why? how solve problem?

there easier way word written in edittext string?

the first error experiencing "the method findviewbyid (int) undefined type r.layout" because have import r; in imports, layout r.layout, not layout view. if layout reference view, findviewbyid() valid method call.

the next error, "the method findviewbyid(int) undefined type generatore" looks because class generatore not inherit activity, hence there no findviewbyid() method available.

without seeing entire class, hard sure problem is. bare minimum required string value of edittext:

public class testactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_layout); edittext text = (edittext) findviewbyid(r.id.edittext); string string = text.gettext().tostring(); // value edittext } }

of course, want fetch text after user inputs, maybe within button click or something, can move text.gettext().tostring() elsewhere, long comes after setcontentview() , findviewbyid().

java android android-edittext findviewbyid

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -