Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Android View Instance

Tags:

android

This is a dumb question and I know the answer is sitting in front of me, I'm just having trouble searching for it in the right way.

I've got a custom view that has been set as the content view and inflated from xml. How can I access the instance to call methods on it from the activity class? I remember seeing something akin to getResourceById() a while back, but now I can't seem to find it and I'm not even sure if that's the best way to do it.

Sorry for the dumb question.

like image 389
Chris Thompson Avatar asked Feb 28 '23 07:02

Chris Thompson


1 Answers

If you have used an inflater, you will be given an instance of a View class. You then use your instance like so

LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = li.inflate(R.layout.small_listview_row, null);

TextView tvItemText = (TextView)row.findViewById(R.id.tvItemText);
like image 96
MattC Avatar answered Mar 07 '23 23:03

MattC