android - Best way of making a class for an object? -


i'm trying create game. need kitten object image displayed. need use object within multiple activities decided it's better using outside class.

i used this. function findviewbyid(int) not aviable outside activity. how this?

public class kitten {     context parent;     view parentview;     imageview imgbody, imghead;      kitten(context context, view view) {         parent = context;         parentview = view;          //create body & head         imgbody = new imageview(parent);         imgbody.setimageresource(r.mipmap.img_kitty_body_white);         addimage(imgbody);         imghead = new imageview(parent);         imghead.setimageresource(r.mipmap.img_kitty_head_white);         addimage(imghead);     }      private void addimage(imageview img) {         relativelayout rl = (relativelayout) findviewbyid(r.id.adoptview);         relativelayout.layoutparams lp = new relativelayout.layoutparams(                 relativelayout.layoutparams.wrap_content,                 relativelayout.layoutparams.wrap_content);         lp.addrule(relativelayout.below, r.id.adoptview);         lp.addrule(relativelayout.align_parent_left);         rl.addview(img, lp);     } } 

the main problem have, within addimage method...

have tried using method specific view? try parentview.findviewbyid()


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -