Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. private void callMeInActivityOnCreate() {
  2. ListView listView = new ListView(this);
  3. CharSequence input = "Uniqueness happens when you fear attitude so authoratively that whatsoever you are sitting is your attraction.\r\n" +
  4. "When the seeker of man experiences the shames of the lover, the sainthood will know individual.\r\n" +
  5. "You have to disturb, and avoid harmony by your failing.\r\n" +
  6. "Hell of happiness will confidently shape a united wind.\r\n" +
  7. "Chaos is the only paradox, the only guarantee of dimension.\n" +
  8. "Light is not occult in over there, the underworld, or wonderland, but everywhere.\n" +
  9. "The embittered life of enlightenment is to follow with sainthood.\n" +
  10. "When one follows tantra and chaos, one is able to study love.\n" +
  11. "The suffering of discovering doers is unconditional.\n" +
  12. "Chaos is not the crystal satori of the sinner.\n" +
  13. "The purpose is a pure lotus.\n" +
  14. "As i have knowed you, so you must handle one another.\n" +
  15. "Reincarnation fears when you believe with totality.\n" +
  16. "Never develop the moon, for you cannot respect it.\n";
  17. StringBuilder sb = new StringBuilder();
  18. for (int i = 0; i < 7000; i++) {
  19. sb.append('#').append(i).append(" ================\n").append(input);
  20. }
  21. listView.setAdapter(new PagingAdapter(sb));
  22. listView.setDivider(null);
  23. listView.setSelector(android.R.color.transparent);
  24. setContentView(listView);
  25. }
  26.  
  27. class PagingAdapter extends BaseAdapter {
  28. /*
  29. sample logcat output:
  30.  
  31. MainActivity D PagingAdapter =================================================
  32. D PagingAdapter text size: 6312890
  33. D PagingAdapter #items: 105002
  34. D PagingAdapter it took: 328ms
  35. D PagingAdapter =================================================
  36. */
  37. CharSequence text;
  38. List<Integer> list = new ArrayList<>();
  39.  
  40. public PagingAdapter(CharSequence text) {
  41. this.text = text;
  42.  
  43. long t0 = System.currentTimeMillis();
  44. int length = text.length();
  45. list.add(-1);
  46. for (int i = 0; i < length; i++) {
  47. if (text.charAt(i) == '\n') {
  48. list.add(i);
  49. }
  50. }
  51. list.add(length);
  52. long t1 = System.currentTimeMillis();
  53. Log.d(TAG, "PagingAdapter =================================================" );
  54. Log.d(TAG, "PagingAdapter text size: " + text.length());
  55. Log.d(TAG, "PagingAdapter #items: " + list.size());
  56. Log.d(TAG, "PagingAdapter it took: " + (t1 - t0) + "ms");
  57. Log.d(TAG, "PagingAdapter =================================================" );
  58. }
  59.  
  60. @Override
  61. public int getCount() {
  62. return list.size() - 1;
  63. }
  64.  
  65. @Override
  66. public Object getItem(int position) {
  67. return null;
  68. }
  69.  
  70. @Override
  71. public long getItemId(int position) {
  72. return 0;
  73. }
  74.  
  75. @Override
  76. public View getView(int position, View convertView, ViewGroup parent) {
  77. TextView tv;
  78. if (convertView != null) {
  79. tv = (TextView) convertView;
  80. } else {
  81. tv = new TextView(parent.getContext());
  82. tv.setTextSize(24);
  83. }
  84. tv.setText(text.subSequence(list.get(position) + 1, list.get(position + 1)));
  85. return tv;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement