Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. public class MainActivity extends ActionBarActivity implements SwipeRefreshLayout.OnRefreshListener {
  2.  
  3. DBAdapter myDb = new DBAdapter(this);
  4.  
  5. private Uri imageUri;
  6. private SwipeRefreshLayout swipeLayout;
  7. private AsyncTwitter twitter;
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13.  
  14. startTwitter();
  15. swipeLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
  16. swipeLayout.setOnRefreshListener(this);
  17.  
  18. try {
  19. myDb.open();
  20. } catch (SQLException e) {
  21. e.printStackTrace();
  22. }
  23.  
  24. populateListViewFromDb();
  25. }
  26.  
  27. private void populateListViewFromDb() {
  28. Cursor c = myDb.getAllRows();
  29.  
  30. //allow activity to manage lifetime of the cursor
  31. //this is deprecated.
  32. startManagingCursor(c);
  33.  
  34. //set up mapping from cursor to view fields
  35. String[] fromFieldNames = new String[]
  36. {DBAdapter.KEY_USERNAME, DBAdapter.KEY_TWEET_TEXT,};
  37. int[] toViewIds = new int[]
  38. {R.id.item_username, R.id.item_tweet_text};
  39.  
  40. //create an adapter to map columns of the db onto the elements of the ui
  41. SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(
  42. this, //context
  43. R.layout.single_photo_item_view, //row layout
  44. c, //cursor
  45. fromFieldNames,
  46. toViewIds
  47. );
  48.  
  49. //set the adapter for the list view
  50. ListView photoList = (ListView) findViewById(R.id.updatedTweets);
  51. photoList.setAdapter(myCursorAdapter);
  52. }
  53.  
  54. <android.support.v4.widget.SwipeRefreshLayout
  55. xmlns:android="http://schemas.android.com/apk/res/android"
  56. xmlns:tools="http://schemas.android.com/tools"
  57. android:layout_width="match_parent"
  58. android:layout_height="match_parent"
  59. android:paddingLeft="@dimen/activity_horizontal_margin"
  60. android:paddingRight="@dimen/activity_horizontal_margin"
  61. android:paddingTop="@dimen/activity_vertical_margin"
  62. android:paddingBottom="@dimen/activity_vertical_margin"
  63. android:id="@+id/refresh"
  64. tools:context=".MainActivity$PlaceholderFragment">
  65.  
  66. <ListView
  67. android:layout_width="fill_parent"
  68. android:layout_height="fill_parent"
  69. android:id="@+id/updatedTweets"/>
  70.  
  71. </android.support.v4.widget.SwipeRefreshLayout>
  72.  
  73. <?xml version="1.0" encoding="utf-8"?>
  74. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  75. android:layout_width="match_parent"
  76. android:layout_height="match_parent">
  77.  
  78. <ImageView
  79. android:layout_width="wrap_content"
  80. android:layout_height="wrap_content"
  81. android:id="@+id/item_photo_view"
  82. android:layout_alignParentTop="true"
  83. android:layout_alignParentLeft="true"
  84. android:layout_alignParentStart="true"
  85. android:maxHeight="120dp"
  86. android:maxWidth="120dp"
  87. android:adjustViewBounds="true"
  88. android:src="@drawable/img_placeholder"/>
  89.  
  90. <TextView
  91. android:layout_width="wrap_content"
  92. android:layout_height="wrap_content"
  93. android:textAppearance="?android:attr/textAppearanceMedium"
  94. android:text="Username"
  95. android:id="@+id/item_username"
  96. android:paddingRight="15dp"
  97. android:layout_toEndOf="@+id/item_photo_view"
  98. android:layout_alignParentTop="true"
  99. android:layout_toRightOf="@+id/item_photo_view"/>
  100.  
  101. <TextView
  102. android:layout_width="wrap_content"
  103. android:layout_height="wrap_content"
  104. android:text="item description"
  105. android:id="@+id/item_tweet_text"
  106. android:layout_alignParentRight="true"
  107. android:layout_alignParentEnd="true"
  108. android:layout_toEndOf="@+id/item_photo_view"
  109. android:paddingLeft="20dp"
  110. android:layout_alignBottom="@+id/item_photo_view"
  111. android:layout_below="@+id/item_username"
  112. android:layout_toRightOf="@+id/item_photo_view"/>
  113.  
  114. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement