Junior — Middle
Kas saaksid anda näiteid meetoditest, mida kasutatakse View-iga töötamisel arenduses?
sobes.tech AI
Vastus AI-lt
In Android, the following methods are commonly used to work with Views:
findViewById(int id)— to find a View by its identifier.setOnClickListener(View.OnClickListener listener)— to set a click handler.setVisibility(int visibility)— to control the visibility of the View (VISIBLE,INVISIBLE,GONE).setText(CharSequence text)— to change the text in a TextView or Button.setBackgroundColor(int color)— to change the background color of the View.invalidate()— to redraw the View.
Example:
Button button = findViewById(R.id.my_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button.setText("Pressed");
button.setBackgroundColor(Color.RED);
}
});