I cannot seem to change the position of an ImageView in my android application. It happens when I place my code in a specific method as explained below.
I am using the IndoorAtlas library in my android project. I downloaded the sample application and got it running on my phone. Works great.
This library has an onServiceUpdate method which is used to handle the location updates. My aim is to move an ImageView whenever the location is updated. Pretty simple.
Here is the original method as provided by the example (works fine for me):
/* IndoorAtlasListener interface */ /** * This is where you will handle location updates. */ public void onServiceUpdate(ServiceState state) { mSharedBuilder.setLength(0); mSharedBuilder.append("Location: ") .append("\n\troundtrip : ").append(state.getRoundtrip()).append("ms") .append("\n\tlat : ").append(state.getGeoPoint().getLatitude()) .append("\n\tlon : ").append(state.getGeoPoint().getLongitude()) .append("\n\tX [meter] : ").append(state.getMetricPoint().getX()) .append("\n\tY [meter] : ").append(state.getMetricPoint().getY()) .append("\n\tI [pixel] : ").append(state.getImagePoint().getI()) .append("\n\tJ [pixel] : ").append(state.getImagePoint().getJ()) .append("\n\theading : ").append(state.getHeadingDegrees()) .append("\n\tuncertainty: ").append(state.getUncertainty()); log(mSharedBuilder.toString()); } Below is the code which I use to update my ImageView's location:
ImageView imgPoint = (ImageView) findViewById(R.id.imagePoint); imgPoint.setX(250); imgPoint.setY(200); If I add these lines to the onServiceUpdate method above, the method doesn't work. Nothing in the onServiceUpdate method runs.
However, if I place these 3 lines in onCreate or any other method, it works great. The ImageView is able to move successfully.
I have also noticed that if I add a Toast or Alert in onServiceUpdate, the same thing happens. The onServiceUpdate method doesn't fire at all.
Toast.makeText(getApplicationContext(), "Hello!", Toast.LENGTH_LONG).show(); This is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="300dp" android:layout_weight="1"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/imageView" android:layout_weight="1" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"> <ImageView android:layout_width="20dp" android:layout_height="20dp" android:layout_marginTop="1dp" android:layout_marginLeft="1dp" android:id="@+id/imagePoint" android:layout_weight="1" /> </RelativeLayout> </RelativeLayout> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> </LinearLayout>