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

hey,

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.
michael22
Freshman
Freshman
 
Posts: 8
Joined: Wed Jan 30, 2008 5:37 pm

Top

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 1.0.8.4

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.031 seconds, using GeSHi 1.0.8.4


Let us know if it helped you. :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
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

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

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 15 guests