Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

touch - Android - ImageView On Click

Im trying to trace a click when my image view is clicked, but I cannot seem to pick up the touch, any ideas?

imgView.setOnClickListener(new View.OnClickListener(){
    public void onClick(View v) {
        Log.v(TAG, " click");
    }
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Images normally aren't clickable, therefore I would suggest that you put the definition

android:clickable="true"
android:focusable="true"

in your layout.xml to the imageView.

If this is not helping, please edit+update your question and show us the part of your layout, where you define the image to have a look at it.

EDIT: Tried it, and your code worked with me too - even with the upper case id name. Can you please have a close look at your LogCat? Mine sometimes doesn't really update, as long as I don't choose the device again.

To do so in Eclipse, go to the View "Devices" (or show it first via "Window") and click once on your device / virtual device.

If you still don't find your log entry in the LogCat-View, try to create a filter (via the green plus and giving it the String you defined with TAG as "by Log Tag").

Have a look at android developers > Using DDMS at the section "Using LogCat"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...