1. Experiment: Use the layout editor to forcibly specify the two buttons with the same ID, and then Code Obtain the handle through findviewbyid () and modify its text.
Experimental results: only the text of one button changes, and the other is not affected.
2. Experiment: Only one linearlayout is put in the main layout, and a new button is dynamically added in the code, which is added multiple times with layout. addview.
Experiment results: discovery Program An error is reported directly to prevent running.
3. Experiment: Put two linearlayout in the main layout. After a new button is added to the Code, add it to two different layout. addview () Layout respectively.
Experiment results: The program directly reports an error and does not run.
4. experiment: put a button ID btn001 in the active activity layout. Create a dialog box and place a button in the layout. The ID is btn001, in the activity and dialog oncreate functions, you can use findviewbyid to search for BTN and modify the text.
Experiment results: the text of both buttons is changed to their own text, which does not affect each other.
5. Experiment: Create a button through new in activity, add the new button to activity, create a dialog box, and add the button to the dialog box.
Experiment result: An error occurred while running the program.
conclusion:
1. the view ID in the same project can be the same. In the r file, the same ID only generates one data item.
2. When two views with the same ID are displayed in the same view, only one of them can be accessed through findviewbyid.
3. the same view (the new handle) can only be managed by one view, and cannot be added to another view or multiple views multiple times. Otherwise, the program runs incorrectly.