Calling findViewById in a unit test case

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

Calling findViewById in a unit test case

Postby lucius.fox08 » Thu Feb 05, 2009 9:23 am

Hi,

I create a dialog using this in my test case:

public class TestMyActivity extends ActivityUnitTestCase<MyActivity>{

public void test1() {

MyActivity myactivity = startActivity(mStartIntent, null, null);


Dialog d = new AlertDialog.Builder(myactivity)
.setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dummy();
}
})

}

}
Then I try to get the 'yes' button using this:
Button yesButton = (Button)d.findViewById(R.string.btn_yes);

But I get null for my 'yesButton'.

Any idea why findViewById does not work? And if not, how can I get a reference to yes button of the dialog?

Thank you.
lucius.fox08
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 15, 2008 3:05 am

Top

Postby Bossly » Fri Feb 20, 2009 2:02 pm

The findViewById using only with ids ( R.id.* ) resources only. :!:
Using android-sdk-windows-2.1
Best wishes, Bossly
User avatar
Bossly
Freshman
Freshman
 
Posts: 8
Joined: Mon Dec 01, 2008 11:03 am

Postby MrSnowflake » Fri Feb 20, 2009 2:29 pm

Bossly wrote:The findViewById using only with ids ( R.id.* ) resources only. :!:
In the current view. In the case of Activity.findViewById() this means, it's going to search in the View you set with setContentView().
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests