Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <LinearLayout
- android:layout_width="match_parent"
- android:orientation="horizontal"
- android:layout_height="wrap_content">
- <TextView
- android:id="@+id/expandableTextView"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- <ImageButton
- android:id="@+id/expandBtn"
- android:src="@drawable/plusIcon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </LinearLayout>
- final int MIN_CHARS = 10;
- String fullText;
- boolean isExpanded;
- TextView textView = (TextView) findViewById(R.id.expandableTextView);
- ImageButton imageButton = (ImageButton) findViewById(R.id.expandBtn);
- fullText = textView.getText().toString();
- textView.setText(fullText.substring(0,MIN_CHARS));
- imageButton.setImageResource(R.drawable.plusIcon);
- imageButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- isExpanded = ! isExpanded;
- imageButton.setImageResource(isExpanded?R.drawable.minusIcon:R.drawable.plusIcon);
- textView.setText(isExpanded?fullText:fullText.substring(0,MIN_CHARS));
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement