简体   繁体   中英

listactivity within an activity is not working(Android)

ok it seems messy

i figured out a way

just teel me that when i call the setonitemclicklistner() it did fired overdirive method?

   getListView().setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

       //i couldn't reach here nor it shows this method

    }
  }); 

help :/

Check this answer .

Your layout listview_for_customlist.xml must contain a ListView like this one:

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

Check this line:

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

You are using a different id, the ListView id of a ListActivity must be android.R.id.list

When you change your Activity to ListActivity you don't need to findViewById for the ListView that has id as list .

You can just write

getListView().setAdapter(adapter);

In your layout change the id for the ListView to android.id="@android:id/list" and use getListView inside your activity to refer to this list view.

Replace the id of your ListView to use the built in android list id @android:id/list

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

Be sure that the id is exactly the same as above.

Then you can get the ListView by doing this

ListView listView = (ListView)findViewById(android.R.id.list);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM