Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends ActionBarActivity implements SwipeRefreshLayout.OnRefreshListener {
- DBAdapter myDb = new DBAdapter(this);
- private Uri imageUri;
- private SwipeRefreshLayout swipeLayout;
- private AsyncTwitter twitter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- startTwitter();
- swipeLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
- swipeLayout.setOnRefreshListener(this);
- try {
- myDb.open();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- populateListViewFromDb();
- }
- private void populateListViewFromDb() {
- Cursor c = myDb.getAllRows();
- //allow activity to manage lifetime of the cursor
- //this is deprecated.
- startManagingCursor(c);
- //set up mapping from cursor to view fields
- String[] fromFieldNames = new String[]
- {DBAdapter.KEY_USERNAME, DBAdapter.KEY_TWEET_TEXT,};
- int[] toViewIds = new int[]
- {R.id.item_username, R.id.item_tweet_text};
- //create an adapter to map columns of the db onto the elements of the ui
- SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(
- this, //context
- R.layout.single_photo_item_view, //row layout
- c, //cursor
- fromFieldNames,
- toViewIds
- );
- //set the adapter for the list view
- ListView photoList = (ListView) findViewById(R.id.updatedTweets);
- photoList.setAdapter(myCursorAdapter);
- }
- <android.support.v4.widget.SwipeRefreshLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:id="@+id/refresh"
- tools:context=".MainActivity$PlaceholderFragment">
- <ListView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:id="@+id/updatedTweets"/>
- </android.support.v4.widget.SwipeRefreshLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/item_photo_view"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:maxHeight="120dp"
- android:maxWidth="120dp"
- android:adjustViewBounds="true"
- android:src="@drawable/img_placeholder"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:text="Username"
- android:id="@+id/item_username"
- android:paddingRight="15dp"
- android:layout_toEndOf="@+id/item_photo_view"
- android:layout_alignParentTop="true"
- android:layout_toRightOf="@+id/item_photo_view"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="item description"
- android:id="@+id/item_tweet_text"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:layout_toEndOf="@+id/item_photo_view"
- android:paddingLeft="20dp"
- android:layout_alignBottom="@+id/item_photo_view"
- android:layout_below="@+id/item_username"
- android:layout_toRightOf="@+id/item_photo_view"/>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement