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

problems with onCellLocationChanged
How to send a image or text file in Android
Use variable defined in one event in other event
Highlighting Sub String in a String
convert StringArray to DateArray
Adding a new page to viewpager appears to be blank
How to activate Bluetooth programatically in android [duplicate]
Dynamic ListView in multiple screens
Play video from ByteArrayOutputStream on android
How to get EditText Text inside ListView
List view postion comes to top after append data
Android Gridview is not refreshed while pressing back button
Android: GCM server side & sending backwards
NullPointer Exception when I pass a variable from one activity to other
CommandLine inside a loop
Best way to get result from Activity in Android API < 16

Categories

HOME
notepad++
django
go
porting
checkstyle
c++11
apache-flink
object
solver
opendj
static-site
spring-session
crystal-reports-2013
mvc5
rcloud
fosrestbundle
little-proxy
commonjs
mod-security
cmdb
endpoint
docx
coin3d
symfony-2.8
atlassian-stash
job-scheduling
google-picker
imessage
xmonad
replication
microsoft-ocr
squashfs
libigl
ember-cli
pimcore
short-url
moses
google-earth
spring-security4
indy10
lubridate
getlasterror
sql-server-ce
projects-and-solutions
recurrent-neural-network
apns-php
softmax
placeholder
angular-http
xbmc
launchctl
azure-cli
spring-data-couchbase
filehandle
skin
cmp
donations
materialized-path-pattern
angular2-testing
mapxtreme
winusb
qtplugin
eigenvector
google-query-language
stream-processing
spreadjs
concept-insights
character-replacement
decimalformat
r-package
include-guards
google-books
visual-sourcesafe-2005
wso2greg
sha512
angular-gettext
webfinger
memset
git-repo
openargs
windows-embedded-standard
artemis
away3d
modular
cocoalibspotify-2.0
merb
pagedown
traceability
resource-management
curb
mkv
jquery-blockui
thttpd
josql
convention
flex-mobile
user-tracking
rmdir
timthumb
tmx
office-2007
purepdf
visualj#
asynchronous-wcf-call
scrubyt
blind

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