How to call findViewById() ??

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to call findViewById() ??

Postby xplagu3 » Sun Oct 18, 2009 11:15 am

I have an adapter class like so

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class KeypadAdapter extends BaseAdapter {
  3.  
  4.     ...
  5.  
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


i would like to call findViewById() from inside this class to access a TextView.

What do i need to do to achieve this?
xplagu3
Freshman
Freshman
 
Posts: 4
Joined: Sat Sep 26, 2009 3:42 pm

Top

Postby qlimax » Sun Oct 18, 2009 8:10 pm

hi, try to pass your Activity to the constructor of your KeyAdapter class,

if you are building the object
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  KeyAdapter k=new KeyAdapter(....)
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
into an Activity you can pass this as constructor parameter

then you can call findViewById on that object you pass.


cya :run:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby xplagu3 » Mon Oct 19, 2009 3:29 am

Thanks for the reply mate

You are right. In particular I was forgetting to cast to context to the correct type before trying to invoke the findViewById()
xplagu3
Freshman
Freshman
 
Posts: 4
Joined: Sat Sep 26, 2009 3:42 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests