Search code examples
androidadapterandroid-adapterlistadapter

Cannot resolve method setListAdapter


Am fairly new to android and am getting this error in my android studio I need help. i get error cannot resolve method setListAdapater(com.ippc.mobileapp.adapter.HotelAdapter) and cannot resolve this.getListView()

// This is a section of my code

public class Hotelinfo extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hotelinfo);


    final List<Video> data = getHotels();

HotelAdapter adapter = new HotelAdapter(this, data);

setListAdapter(adapter);

    this.getListView().setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
                                long arg3) {

            launchWebActivity(data.get(pos).getUrl(),   data.get(pos).getTitle());
        }

    });

Solution

  • As you extended AppCompatActivity, which doesn't inherit from ListActivity, you can't use setListAdapter().

    You need to add the ListView to your layout and then use ListView.setAdapter().

    yourListView.setAdapter(adapter);