android


Button android while pressed


I want to print something while my button is pressed (not after it is released).
At moment I have this, but it only works once...
button.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
System.out.println("pressed");
return true;
}
return false;
}
});
System.out doesn't work in an Android Device (won't show you anything on the device)
and if you have a text view you can set the text on your MotionEvent.ACTION_DOWN as you are already doing and on the MotionEvent.ACTION_UP you set your text of your text view to empty.
Something like this:
public class TestActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
final TextView textView = (TextView) findViewById(R.id.textview);
final Button button = (Button) findViewById(R.id.button);
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
textView.setText("Button Pressed");
}
if(event.getAction() == MotionEvent.ACTION_UP){
textView.setText(""); //finger was lifted
}
return true;
}
});
}
}
try this to continously print pressed message while you are pressing it.
button.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
System.out.println("pressed");
return false;
}
});

Related Links

ActionBar , TabLayout are leaving (unnecessary ) space after become hidden , Gone
Graphhopper Set up android
How can I change the default SQLite timezone
android accelerometer bandwidth
Android Runtime Permissions - App Crashes when user revokes permission. How to handle it?
Disable automatic publishing on Google Play
Android Studio Toolbar With NO Layouts
How does AppIndex.AppIndexApi work?
Genymotion virtual device loads too slow
How to get programmatically, Android Application stats without root?
Keeping React native app opened after opening another app
How to clear data in listview and load new data in listview in android on swipe to refresh?
Unity - can't see canvases after updating to 5.3.5? But they are still there?
SignalR vs Google Cloud Messaging
Why Proguard runs despite having minifyEnabled in gradle config?
Parse: push notification GCM Android not delivered via Parse

Categories

HOME
wakanda
fftw
newrelic
alsa
visual-studio-emulator
polling
data-visualization
boto3
accessibility
vimdiff
redis-sentinel
naivebayes
onedrive-api
mongodb-csharp
dpdk
postscript
imageresizer
displaytag
google-api-client
windows-server-2003
fat
gpio
bulletphysics
motion-detection
ms-access-2003
handler
user-defined-functions
bioinformatics
alm
custom-controls
recurring-events
linkedhashmap
gnat-gps
instantiation
openwhisk
dynamic-jasper
getpixel
carriage-return
processwire
batching
getlasterror
reactivekit
xdocreport
z-notation
protein-database
sim-card
health-monitoring
branching-and-merging
claims
lpsolve
httr
optimizely
plan-9
textsum
pair-programming
azure-cli
compiler-design
reshape
cmp
cd-burning
node-request
beamer
i386
angular-ui-typeahead
phpwebsocket
fuzzywuzzy
phpgrid
state-restoration
vhosts
tfs-workitem
jdi
xvim
dock
zscript
dulwich
sha512
aspectj-maven-plugin
jbake
post-commit-hook
easyrtc
punycode
xml-dsig
twitter-bootstrap-rails
visual-studio-express
kendo-dataviz
mbunit
printdialog
kogrid
vfs
saleslogix
iboutlet
fusefabric
ilasm
infobright
cgimage
mysql-error-1205
cgbitmapcontextcreate
nhprof
objective-j
uideviceorientation
ie-compatibility-mode
ajax-polling
qtabbar
interop-domino
information-management

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