updating own views on click

Put your problem here if it does not fit any of the other categories.

updating own views on click

Postby michael22 » Sat Feb 02, 2008 5:38 am


i have an own ImageView, which is declared in via xml

<org.michael.MyView ... />

the class now overrides onDraw to draw some contents. it has also some extending methods to pass arguments from outside. i now want to update the drawing from time to time, but i dont know how. because i dont initialize the class like "MyView mv = new MyView()" i just have the Reference to the ImageView using getViewById. but i need to call mv.setParam(123) for e repaint. any ideas?

For example: when im using the progressbar i can define it in the xml file. when calling
ProgressBar pb = (ProgressBar) findViewById(R.id.progressbar);
the variable pb hast the method setProgress(int).
when using my own view, android does not offer the declared methods needed.
Posts: 8
Joined: Wed Jan 30, 2008 5:37 pm


Postby plusminus » Sat Feb 02, 2008 11:52 am

Hello michael22,

I did that in the :src: WeatherForecast-Tutorial. It works like this:

Somewhere in your xyzlayout.xml-file:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <org.anddev.android.weatherforecast.views.SingleWeatherInfoView
  2.         id="@+id/weather_1"
  3.         android:layout_width="wrap_content"
  4.         android:layout_height="wrap_content"
  5.         android:gravity="center_horizontal"
  6.         android:orientation="vertical"
  7.         />
Parsed in 0.001 seconds, using GeSHi

Then in your Activity (setRemoteImage is a custom method on the custom view):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // the Cast to SingleWeatherInfoView is important...
  2. ((SingleWeatherInfoView) findViewById(R.id.weather_1)).setRemoteImage(imgURL);
  3. // or the same in two lines:
  4. SingleWeatherInfoView swiv = (SingleWeatherInfoView)findViewById(R.id.weather_1);
  5. swiv.setRemoteImage(imgURL);
Parsed in 0.016 seconds, using GeSHi

Let us know if it helped you. :)

Image | Android Development Community / Tutorials
User avatar
Site Admin
Site Admin
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby michael22 » Sat Feb 02, 2008 1:46 pm

thx for the answer.. but i dont get it, that is exactly my code.
after sleeping over this, it worked for me today.. dont know why.. maybe i just shouldnt work till 7am... ;)

but that leads to the next problem. i can now change the value i needed, but i cant call repaint() in an ImageView. How can i force the application to repaint?

UPDATE: Solved using the handler in the pizza tutorial

Posts: 8
Joined: Wed Jan 30, 2008 5:37 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 3 guests