0

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..

Michaël
  • 3,679
  • 7
  • 39
  • 64
User
  • 509
  • 2
  • 8
  • 23
  • 2
    Please show your logcat. May be you want to save the 'Content' in sharedprefrences and use it here. – Prachi Sep 10 '13 at 12:11

2 Answers2

2

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

to

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

Vishal Pawale
  • 3,416
  • 3
  • 28
  • 32
1

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

TextView txt=(TextView)view.findViewById(R.id.content);
Eric Kogi
  • 89
  • 1
  • 6