यह थोड़ा लंगड़ा सवाल होने जा रहा है। मेरे पास निम्न कोड है:एंड्रॉइड :: findViewByID - मैं किसी अन्य UI तत्व के श्रोता के माध्यम से टेक्स्ट व्यू का दृश्य कैसे प्राप्त कर सकता हूं?
..............
public void onCreate (Bundle bundle)
{
super.onCreate(bundle);
this.setContentView(R.layout.main2);
Button bnt = (Button) this.findViewById(R.id.browser);
bnt.setOnClickListener(new ButtonListener());
}
..............
class ButtonListener implements android.view.View.OnClickListener
{
public void onClick(View v)
{
// I have a TextView in my xml layout file.
// I'd like to get it and change my text when I click this button.
// But I can't get it (the TextView) unless I make it as a value of a static member of this class and pass it to the constructor.
//I believe I am missing a big point here, so i'd be very thankful if you could explain how this is meant to be done ?
}
}
किसी भी मदद की सराहना की जाती है।
मेरा बिंदु बिल्कुल जांचें। देखें माता-पिता = (देखें) v.getParent() - मैंने इसे इस तरह लिखा है - .getParent() एक ViewParent ऑब्जेक्ट देता है। फिर भी, यह वही था जो मैं खोज रहा था। धन्यवाद। – George
आपके रूट लेआउट तत्व को एक आईडी देने का और अधिक मजबूत तरीका होगा और आपके 'onCreate() 'में' findViewById()' करें। तो आपके पास अपने लेआउट और अंदर के सभी विचारों तक पूर्ण पहुंच है। तो राहुल ने सही जवाब दिया है ... टेक्स्टव्यू – WarrenFaith