android


The method onListItemClick(ListView, View, int, long) of type MainActivity must override or implement a supertype method


I just changed a ListActivity to Activity, and everything works fine except the code that makes the activity do something if click on List Item (onListItemClick).
I get this error:
The method onListItemClick(ListView, View, int, long) of type MainActivity must override or implement a supertype method
#Override
protected void onListItemClick(ListView lv, View v, int position, long id) {
super.onListItemClick(lv, v, position, id);
// Do something
}
( This class was extending ListActivity and everything works fine, but now I want it to extend Activity).
Everything works fine except for this code.
Your issue is that you'd extends as ListActivity and after some time you had removed ListActivity and extend your class to Activity. onListItemClick is an override method of ListActivity which is not available in Activity
Solution : If you want to use ListItemClick in Activity so you can do it by following ways else you need to extends your MainClass with ListActivity instead of Activity
There are 2 ways to setOnItemClickListener to the ListView while using Activity
- Implement OnItemClickListener to your Activity
public class MyActivity extends Activity implements OnItemClickListener {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
}
- Write ListView's setOnItemClickListener
mListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
If you have change from ListActivity to Activity then you have to change onListItemClick to urListView.setOnItemClickListener method. Just Like,
urListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
}
});

Related Links

How do i use a dialogue in my android app just before the start of service?
Map is not shown in android
Two-way binding cannot resolve a setter for java.lang.String property
BasicNetwork.performRequest: Unexpected response code 429 (android)
Telerik Listview for android swipe clossing automatically
Set the time of time picker dialogue to the selected time
How to get text in EditText with ListView and adapter
Making a App for tablets with certain requirements
SubscriptionManager to read IMSI for dual SIM devices ruuning Android 5.1+
How I can call showinfowindow() in a marker within cluster manager?
Save battery by not drawing on every render call
How to create a query of array of json objects with retrofit2
Play audio Stream with AudioTrack in Marshmallow
Android Cursor initialization [duplicate]
Facebook login not logging in after log out Android
RecyclerView: new loaded items will not be added to top

Categories

HOME
android
google-cloud-platform
alexa-skills-kit
pyqt
pclxl
gembox-spreadsheet
data-visualization
arangodb
ycsb
stellar.js
supervisor
3nf
parameter-passing
azure-powershell
coin3d
template-engine
googlebot
ksh
ember-cli
postscript
mongoid6
short-url
monit
roundup
draft-js-plugins
custom-post-type
stackexchange
jasmine-node
progress-bar
apktool
quantlib
user-defined-functions
xbox
quickfixj
spring-security4
vue-chartjs
playframework-2.1
dm-script
cd
xdocreport
attributeerror
photos
httr
mesosphere
tinymce-3
payara-micro
oracleclient
py2neo
baidu
javafx-css
reachability
smartfoxserver
autosar
reporting-services-2012
signalr.client
expectations
freepbx
relativelayout
character-replacement
binomial-theorem
lasso
haskell-warp
linked-tables
cwrsync
canvg
jquery-forms-plugin
android-broadcast
qtwebengine
adehabitathr
nodelist
jbake
cocos3d
codeplex
dct
synapse
android-audiorecord
syndicationfeed
mt4j
embedded-fonts
cnf
process-explorer
sqlclr
wimax
xcode3.2
os.system
listitem
correlated-subquery
infobright
procedures
drawtobitmap
mbeans
msr
django-paypal
facebook-iframe
django-piston
wcf-instancing
interop-domino
asynchronous-wcf-call
unmanagedresources

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App