Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <LinearLayout
  2. android:layout_width="match_parent"
  3. android:orientation="horizontal"
  4. android:layout_height="wrap_content">
  5. <TextView
  6. android:id="@+id/expandableTextView"
  7. android:layout_width="0dp"
  8. android:layout_height="wrap_content"
  9. android:layout_weight="1"/>
  10. <ImageButton
  11. android:id="@+id/expandBtn"
  12. android:src="@drawable/plusIcon"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content" />
  15. </LinearLayout>
  16.  
  17. final int MIN_CHARS = 10;
  18. String fullText;
  19. boolean isExpanded;
  20.  
  21. TextView textView = (TextView) findViewById(R.id.expandableTextView);
  22. ImageButton imageButton = (ImageButton) findViewById(R.id.expandBtn);
  23.  
  24. fullText = textView.getText().toString();
  25. textView.setText(fullText.substring(0,MIN_CHARS));
  26. imageButton.setImageResource(R.drawable.plusIcon);
  27. imageButton.setOnClickListener(new View.OnClickListener() {
  28. @Override
  29. public void onClick(View v) {
  30. isExpanded = ! isExpanded;
  31. imageButton.setImageResource(isExpanded?R.drawable.minusIcon:R.drawable.plusIcon);
  32. textView.setText(isExpanded?fullText:fullText.substring(0,MIN_CHARS));
  33. }
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement