Reputation: 1826
i have a small query, Suppose we start an activity using intents
startActivity(intent);
and a new screen opens up with content in it,like buttons and text fields I just need to know if its possible to fetch the details about the layout and its contents.
I think its not possible, but just wanted to get a proper confirmation.
Upvotes: 0
Views: 70
Reputation: 67502
No, it's not possible to do this. And (from comments) no, it's not possible to "click" a button from a separate Activity
. What you can do, however, is this:
// Calling code:
intent.putExtra(getPackageName() + ".click_me", R.id.your_button); // getPackageName() is for best practices
startActivity(intent);
// In your Activity:
Intent intent = getIntent(); // Get the Intent we used to launch this
int buttonToClick = intent.getIntExtra(getPackageName() + ".click_me", 0); // Get the integer
if (buttonToClick != 0) { // If it's 0, we didn't specify it
View toClick = findViewById(buttonToClick); // Find the View
if (toClick != null && toClick instanceof Button) { // If the View exists, and is a Button..
((Button) toClick).performClick(); // ..then click it
}
}
You provide the Intent
that starts the Activity
with an integer. This integer represents a View
(more specifically, a Button
). Once the Activity
receives it, it finds the matching View
, checks if its a Button
, then performs a click action on it.
This way, you're just passing the integer ID of an item to click, and your opened Activity
just handles the rest.
Upvotes: 1
Reputation: 22527
You can get the contents using getChildAt()
for(int i=0; i<((ViewGroup)v).getChildCount(); ++i) {
View nextChild = ((ViewGroup)v).getChildAt(i);
}
Upvotes: 0