How to Use Getlistview() in Activity

getListView is missing

Your activity must inherit from a ListActivity. Your class should start with

public class MyListAdapter extends ListActivity {

...

}

Then you can use the method

getListView()

This is the official documentation

Second solution

If you use a fragment, then you can access your ListView by using

ListView lv = (ListView) rootView.findViewById(R.id.id_of_your_listView);

The rootView is the view you get in your onCreateView Method of the Fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.example_fragment, container, false);

return rootView;
}

Undefine getlistview method in activity

Please try following:

ListView lv = (ListView) findViewById(R.id.list);

Android - ListActivity to Activity

If you are using ListActivity then in your xml file just change this for ListView id

 android:id="@android:id/list" 

and in your Activity call this

ListView lv = getListView();

If you are using Activity then just find id of your ListView in your java file by

Listview mListView = (ListView) findViewById(R.id.myListView);

and set adapter for that

mListView.setAdapter(mAdapter);


Related Topics



Leave a reply



Submit