Guest User

Untitled

a guest
Jun 21st, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. CursorAdapter slow/jerky scroll
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical"
  7. android:id="@+id/layout_query_viewer">
  8.  
  9. <TextView
  10. android:id="@+id/query_table_name"
  11. style="@style/ActivityTitle" />
  12.  
  13. <HorizontalScrollView
  14. android:id="@+id/hsvMainContent"
  15. android:scrollbars="none"
  16. android:layout_width="fill_parent"
  17. android:layout_height="fill_parent">
  18.  
  19. <LinearLayout
  20. android:id="@+id/llMainContent"
  21. android:orientation="vertical"
  22. android:layout_width="fill_parent"
  23. android:layout_height="fill_parent">
  24.  
  25. <LinearLayout
  26. android:id="@+id/fixed_headers"
  27. android:layout_width="fill_parent"
  28. android:layout_height="wrap_content" />
  29.  
  30. <ListView
  31. android:id="@android:id/android:list"
  32. android:layout_width="fill_parent"
  33. android:layout_height="fill_parent"/>
  34. </LinearLayout>
  35. </HorizontalScrollView>
  36. </LinearLayout>
  37.  
  38. private class QueryAdapter extends CursorAdapter {
  39. public QueryAdapter(Context context) {
  40. super(context, null);
  41. }
  42.  
  43. @Override
  44. public View newView(Context context, Cursor cursor, ViewGroup parent) {
  45. /*
  46. * I'm deliberately not inflating here as I'm synchronizing a remote
  47. * database, so I don't know how many columns my query will return.
  48. */
  49. LinearLayout layout = new LinearLayout(context);
  50. ViewHolder holder = new ViewHolder(cursor.getColumnCount());
  51. layout.setTag(holder);
  52.  
  53. for (int i = 1; i < cursor.getColumnCount(); i++) {
  54. TextView cell = new TextView(context);
  55.  
  56. holder.cells[i] = cell;
  57.  
  58. cell.setBackgroundColor(Color.WHITE);
  59. cell.setMinimumWidth(mColumnWidths[i]);
  60. cell.setPadding(1, 1, 1, 1);
  61.  
  62. layout.addView(cell);
  63. }
  64.  
  65. return layout;
  66. }
  67.  
  68. @Override
  69. public void bindView(View view, Context context, Cursor cursor) {
  70. ViewHolder holder = (ViewHolder)view.getTag();
  71.  
  72. for (int i = 1; i < cursor.getColumnCount(); i++) {
  73. holder.cells[i].setText(cursor.getString(i));
  74. }
  75. }
  76. }
  77.  
  78. static class ViewHolder {
  79. TextView[] cells;
  80.  
  81. public ViewHolder(int size) {
  82. cells = new TextView[size];
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment