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

Unable to open an Android TV application after installing it
Upload image sequentially to a REST API via retrofit
RecyclerView not refreshing after rotating the device with an open DialogFragment
Set the TextView to fill all other area leaving the ImageView Space Using XML -Android
Hide marker when my location get on it and show it again when i leave
Android save state of buttons in grid
PageTransformer'd VerticalViewPager: How to get partial view of next page?
what should be the dimensions of image for imageButton in Android Studio?
android-nullpointer exception when retrieving json array from web service [duplicate]
Android Studio export apk error: Error: Expected resource of type styleable [ResourceType]
Loading / Scaling A Large Batch Of Images
Retrieve All Supported Orientations in Android App
Getting NPE when implementing interface callbacks between adapter and fragment
Multithreaded HTTP Request Queue System Approach
How can I get the network status?
Position index always returns 0 in getView and the program breaks

Categories

HOME
django
jax-rs
saml-2.0
appcelerator
scripting
alsa
cakephp-3.4
zip
google-cloud-datalab
crystal-reports-2013
discrete-mathematics
teechart
sendgrid-api-v3
little-proxy
owin
drop-down-menu
ibeacon-android
pega
x-cart
naivebayes
fileserver
asciidoctor-pdf
rubymotion
libigl
dpdk
backpack-for-laravel
gulp-watch
angular-routing
zxing
resourcebundle
direct3d11
ckfinder
pic32
exchangewebservices
boost-asio
dotspatial
database-comparison
angularjs-material
memory-address
sendbird
sharding
nested-lists
git-rewrite-history
google-earth-engine
ogc
chronicle-map
outputcache
photos
show-hide
servermanager
nanoc
magento-2.0.7
term
openblas
custom-font
oozie-coordinator
type-theory
cmp
jtree
juice-ui
rmongo
polyline
simplepie
cubism.js
autosar
flex-monkey
spring-cloud-feign
signalr.client
gogs
vorpal.js
embedding
tracker-enabled-dbcontext
bizagi
kiosk
html-to-pdf
toast
inf
themoviedb-api
lazybones
batik
typeconverter
cosine-similarity
primitive-types
sonarqube-5.0
rmysql
ray
extjs2
visual-studio-express
mbunit
jeromq
curb
filemerge
mysql-error-1205
umra
ruby-1.8
load-time
eclipse-marketplace
request-headers
data-mapping
xpsdocument
information-management
movieplayer
appliance

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