android


onItemClick works but onItemLongClick does not, why?


i like to share item when long click on it, i use onItemClick to go to another intent and use onItemLongClick for share but onItemLongClick not work please help me
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
ViewHolder ocHolder = (ViewHolder)view.getTag();
TextView ocTextID =(TextView)ocHolder.txtID;
TextView ocTextDsc =(TextView)ocHolder.txtDsc;
Intent intents = new Intent(Intent.ACTION_SEND);
intents.setType("text/plain");
String my_string = ocTextTitle.getText().toString();
intents.putExtra(Intent.EXTRA_TEXT, my_string);
startActivity(Intent.createChooser(intents, "Share this text via"));
return false;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
ViewHolder ocHolder = (ViewHolder)view.getTag();
TextView ocTextID =(TextView)ocHolder.txtID;
TextView ocTextTitle =(TextView)ocHolder.txtTitle;
Intent i = new Intent(hozeactivity.this, ChildList.class);
i.putExtra("pId", ocTextID.getText().toString() );
i.putExtra("uName", ocUser );
i.putExtra("pass", ocPass);
i.putExtra("isOnline", isOnline);
startActivity(i);
}
Change return false; to return true; to tell the View you'd be processing the event. Modify your code as follows:
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
ViewHolder ocHolder = (ViewHolder)view.getTag();
TextView ocTextID =(TextView)ocHolder.txtID;
TextView ocTextDsc =(TextView)ocHolder.txtDsc;
Intent intents = new Intent(Intent.ACTION_SEND);
intents.setType("text/plain");
String my_string = ocTextTitle.getText().toString();
intents.putExtra(Intent.EXTRA_TEXT, my_string);
startActivity(Intent.createChooser(intents, "Share this text via"));
return true;
}
Also make sure the ListView registers the setOnItemLongClickListener() :
myListView.setOnItemLongClickListener(listener);

Related Links

Push notifications are not received when app is not running
Start Pebble app from a watchapp
Robolectric getNextStartedActivity always returns launcher activity
Same shape with different colors in Android
Redirect to another activity when finished service - Android?
Prevent taking a screenshot in android
OkHttp Response caching not works
How can I post my status on facebook using Graph API in android
how to hide OpenGLRenderer in debug (android studio)
How to add Tool bar title at the center of layout
Modify android keyboard to take “http://” or “https://”
When typing in text the image is not resizing android
How to show Text depending of Image and Image's position
How do I update a TextView with data from a SQLite database?
Slide in animation immediately after shared element transition is done
Map events are never called

Categories

HOME
paraview
merge
css3
swt
static
jsf-2.2
vscode-extensions
limit
jquery-ui
android-json
iis-6
crystal-lang
google-schemas
distribution
tput
shared-libraries
mongodb-csharp
keytool
scsi
null-pointer
html5-appcache
breadth-first-search
visual-glitch
named-entity-recognition
ember-cli
pylons
apktool
autodesk-designautomation
postback
utorrent
hreflang
pdw-file-browser
apiary.io
hivemq
magento-1.9.2.4
google-knowledge-graph
openalpr
password-protection
bc
recurrent-neural-network
gdata
metaprogramming
branching-and-merging
importerror
ntvs
proget
automapper-5
mschart
dtsearch
datamaps
podscms
context-sensitive-grammar
boxing
arules
py2neo
taocp
chromium-os
cubism.js
actor-platform
latin
flex4.6
ng-grid
appscale
swizzling
http-status-code-401
hadoop-partitioning
false-sharing
cycle2
sapi
decimalformat
iokit
lazybones
flock
zen-cart
dock
.bash-profile
batik
finalbuilder
viewer
formview
entry-point
codeplex
fpdi
android-audiorecord
http-patch
oocss
gpars
process-explorer
route-provider
scmmanager
diem
insert-id
cardreader
alice
fusefabric
screen-size
automationelement
sifr
echo3
perl5.12
information-management
appliance
commercial-application
idatareader

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