Reputation: 3520
Here is what I want. I want to have a gallery of custom views of layouts. However I want to be able to set setText on textViews within each layout element of the gallery. I am displaying the blank layouts successfully in a gallery view.
However, when I try to setText on a resource from the layout I get a NullPointer exception on the setText function. It says it cannot find my textView.. Here is my code for the getView in my custom Adapter for my gallery.
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflator.inflate(R.layout.adapter_layout, null);
convertView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TextView text1 = (TextView) findViewById(R.id.text1);
//NULL POINTER HERE !!!!
text1.setText("YOYOYOYOYOYO");
}
Upvotes: 0
Views: 790
Reputation: 30168
You're calling findViewById()
on the activity, not the view returned by the inflator. Try
TextView text1 = (TextView) convertView.findViewById(R.id.text1);
Upvotes: 1