Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get reference to ListView from Adapter in Android?

Is it possible to get reference to ListView from Adapter in Android without passing it as an argument to constructor?

like image 868
Taras Avatar asked Nov 28 '12 09:11

Taras


People also ask

How do you connect an adapter with ListView write down the codes for it?

Attaching the Adapter to a ListView // Construct the data source ArrayList<User> arrayOfUsers = new ArrayList<User>(); // Create the adapter to convert the array to views UsersAdapter adapter = new UsersAdapter(this, arrayOfUsers); // Attach the adapter to a ListView ListView listView = (ListView) findViewById(R. id.

How is it possible to view a list in Android?

Android ListView is a ViewGroup that is used to display the list of items in multiple rows and contains an adapter that automatically inserts the items into the list. The main purpose of the adapter is to fetch data from an array or database and insert each item that placed into the list for the desired result.

Which is better ListView or RecyclerView?

Simple answer: You should use RecyclerView in a situation where you want to show a lot of items, and the number of them is dynamic. ListView should only be used when the number of items is always the same and is limited to the screen size.

How do you populate a ListView?

To add rows to a ListView you need to add it to your layout and implement an IListAdapter with methods that the ListView calls to populate itself. Android includes built-in ListActivity and ArrayAdapter classes that you can use without defining any custom layout XML or code.


1 Answers

It is definitely possible. Should it be done or not (Yes there are cases).

// See this method of your adapter
// The parent is the view you are looking for
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
    ListView view = (ListView)parent;
}
like image 100
Pulkit Sethi Avatar answered Oct 05 '22 05:10

Pulkit Sethi