Passing values from one activity to a class that extends View class
I have a need where i must pass some values from an Activity to another file which extends View class (instead of Activity) .... Its not the normal passing of values from one activity to another...
In my Activity,i will pass some co-ordinate values to the class that ex开发者_运维技巧tends View... In this class,i will draw an image and place points over the image on the co-ordinates that were passed from the activity... But , the problem is ,i cant send values using Intent ...
Is there any way to do this??
If you want to show the View, you must use another Activity (you cannot just show a View without an activity holding it), thus this is actually the normal passing of values from one activity to another... the only difference is that once your second activity has received the values, it will have to configure your custom view with them.
Take a look at these links: Building Custom Components, Creating custom Views. In order to use a custom View, you just put it in your XML as you normally do for android Views. For instance:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="this is a normal view"/>
<!-- this is a custom View -->
<your.package.YourCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
精彩评论