Domanda

I am inflating a layout in the viewpager of the current activity but I need to set the textview text of this layout so that I can inflate it and it displays the new text I am doing :

LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.mylayout, null);
TextView txt=(TextView)findViewById(R.id.content);
txt.setText(cursor.getString(cursor.getColumnIndex("Content")));

but that's getting me a nullpointerexception, how can I solve this how can I set the text of the textview of a layout that I am not in which mean from outside this layout..

È stato utile?

Soluzione

Change - TextView txt=(TextView)findViewById(R.id.content);

to

TextView txt=(TextView)view.findViewById(R.id.content);

Altri suggerimenti

To find the textView you want you must specify the parentView and so

TextView txt=(TextView)view.findViewById(R.id.content);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top