OnTouchListener is not able to change ImageResource

by Justin Anderson » Mon, 07 Sep 2009 09:13:10 GMT


Sponsored Links
 I'm not sure offhand why this crashes, but it could be any number of
reasons...  If you could post the logcat output, that would be very helpful.

Also, I was wondering what you were trying to accomplish with this?  If you
are trying to change the image when a touch event occurs and then have it
change back when the touch event is done, you may want to consider using a
selector drawable instead...

It allows you to specify a single drawable that will change based on the
state of the object... i.e. onFocus, onPressed, etc....

I just barely figured out how to do that and there wasn't a whole lot of
documentation available.  If that is what you are trying to do I will post
again with how to do that...

Thanks,
Justin

----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Customized AnalogClock widget doesn't survive screen orientation change

Hello,

I've created a simple analog clock widget for SonyEricsson X10 mini
pro. It just changes the style of standard android AnalogClock widget.
Widget works fine until screen orientation changes when I slide the
physical keyboard. At this moment I recieve the following error:

W/AppWidgetHostView( 1305): updateAppWidget couldn't find any view,
using error
view
W/AppWidgetHostView( 1305): android.view.InflateException: Binary XML
file line
#12: Error inflating class android.widget.AnalogClock
W/AppWidgetHostView( 1305):     at
android.view.LayoutInflater.createView(Layout
Inflater.java:513)
W/AppWidgetHostView( 1305):     at
com.android.internal.policy.impl.PhoneLayoutI
nflater.onCreateView(PhoneLayoutInflater.java:56)
W/AppWidgetHostView( 1305):     at
android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:563)
W/AppWidgetHostView( 1305):     at
android.view.LayoutInflater.rInflate(LayoutIn
flater.java:618)
W/AppWidgetHostView( 1305):     at
android.view.LayoutInflater.inflate(LayoutInf
later.java:407)
W/AppWidgetHostView( 1305):     at
android.view.LayoutInflater.inflate(LayoutInf
later.java:320)
W/AppWidgetHostView( 1305):     at
android.widget.RemoteViews.apply(RemoteViews.
java:900)
W/AppWidgetHostView( 1305):     at
android.appwidget.AppWidgetHostView.updateApp
Widget(AppWidgetHostView.java:208)
W/AppWidgetHostView( 1305):     at
android.appwidget.AppWidgetHost.createView(Ap
pWidgetHost.java:217)
W/AppWidgetHostView( 1305):     at
com.sonyericsson.homescreen.HomeScreen.create
AppWidget(HomeScreen.java:1026)
W/AppWidgetHostView( 1305):     at
com.sonyericsson.homescreen.HomeScreen.access
$3100(HomeScreen.java:105)
W/AppWidgetHostView( 1305):     at
com.sonyericsson.homescreen.HomeScreen$Widget
LoaderThread.run(HomeScreen.java:2423)
W/AppWidgetHostView( 1305): Caused by:
java.lang.reflect.InvocationTargetExcepti
on
W/AppWidgetHostView( 1305):     at
android.widget.AnalogClock.<init>(AnalogClock
.java:62)
W/AppWidgetHostView( 1305):     at
java.lang.reflect.Constructor.constructNative
(Native Method)
W/AppWidgetHostView( 1305):     at
java.lang.reflect.Constructor.newInstance(Con
structor.java:446)
W/AppWidgetHostView( 1305):     at
android.view.LayoutInflater.createView(Layout
Inflater.java:500)
W/AppWidgetHostView( 1305):     ... 11 more
W/AppWidgetHostView( 1305): Caused by: java.lang.RuntimeException:
Can't create
handler inside thread that has not called Looper.prepare()
W/AppWidgetHostView( 1305):     at
android.os.Handler.<init>(Handler.java:121)
W/AppWidgetHostView( 1305):     at
android.widget.AnalogClock.<init>(AnalogClock
.java:52)
W/AppWidgetHostView( 1305):     ... 15 more

My code is here:

public class ClockWidget extends AppWidgetProvider
{
    public void onReceive(Context context, Intent intent)
    {
        String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
        {
            RemoteViews views = new
RemoteViews(context.getPackageName(), R.layout.widget);
AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS),
views);
        }
    }
}

And layout file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                                android:id="@+id/Widget"
                                android:layout_width="fill_parent"
                                android:layout_height="fill_parent"
                                android:gravity="center">
        <AnalogClock android:saveEnabled="true" android:id="@+id/AnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:dial="@drawable/
widgetdial" android:hand_hour="@drawable/widgethour"
android:hand_minute="@drawable/widgetminute"/>
</RelativeLayout>

Could you please advise what can cause such problem.

Thanks,
Alexander

-- 

2. Video not getting played from URL, same video is getting played locally

Hi All,

I am trying to play video on my application. The video files are
hosted in my server and I am using the VideoView to play them.

The problem I am facing is that no video is shown in the screen. The
logcat only shows the amount of buffering but it does not shows any
type of codec that has been used to pay the video

Surprisingly if i transfer the same file to my sdcard and use the
default player, it plays fine saying that MPEG4 codes is been used.

What may be the problem.

Kindly Help

Here is my code for the reference-

setContentView(R.layout.videoplayer);
Bundle bundle = getIntent().getExtras();

VideoView videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setOnPreparedListener(this);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);

Uri video = Uri.parse("http://newshunt.biz/Test/video/Test/
outputfile.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();

-- 

3. Capture image with Intent

4. Why doesn't Cursor expose useful and public features of SQLiteCursor?

5. [WTA]Google Calendar dan default notification

6. Tanya...

7. HttpURLConnection gives UnknownHostException