Skip to content

Instantly share code, notes, and snippets.

@rajajawahar
Created February 3, 2018 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajajawahar/d6c4b9d47ac54ba0ab38576d1fc035d6 to your computer and use it in GitHub Desktop.
Save rajajawahar/d6c4b9d47ac54ba0ab38576d1fc035d6 to your computer and use it in GitHub Desktop.
Change the textview attributes programatically while clicking
TextView textView = new TextView(this);
textView.setText("Test");
textView.setId("Your Id");
textView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
changeTextViewAttributes()
}
});
RelativeLayout.LayoutParams layoutParams =
new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
textView.setLayoutParams(layoutParams);
relativeLayout.addView(textView);
public void changeTextViewAttributes(View view) {
TextView tv = (TextView) view;
switch (view.getId()) {
case 0:
//change the attributes
break;
case 1:
break;
case 2:
break;
case 3:
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment