user2107365
user2107365

Reputation: 23

what is use of ViewGroup in getView method of baseadapter

i am implementing custom listview, i that i am using getView method with ViewGroup, but i do not know what is the exactly use of ViewGroup, can anybody explain me what is the use of ViewGroup, if you give an example then it will be the best

 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     View rowView = inflater.inflate(R.layout.rowlayout, parent, false);

Upvotes: 2

Views: 3344

Answers (2)

Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40186

From documentation https://developer.android.com/reference/android/widget/Adapter.html#getView(int,android.view.View android.view.ViewGroup)

Get a View that displays the data at the specified position in the data set. You can either create a View manually or inflate it from an XML layout file. When the View is inflated, the parent View (GridView, ListView...) will apply default layout parameters unless you use inflate(int, android.view.ViewGroup, boolean) to specify a root view and to prevent attachment to the root.

parent - The parent that this view will eventually be attached to

Upvotes: 1

Nitesh Tiwari
Nitesh Tiwari

Reputation: 4762

ViewGroup helps to hold multiple Views together.

E.g. You can consider ViewGroup as your Layout and TextView as the View.

That means your ViewGroup contains View as a TextView.

Upvotes: 0

Related Questions