Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Created the ListView, ArrayList, and ArrayAdapter. Then we attached t…
Browse files Browse the repository at this point in the history
…he ArrayAdapter to the ListView.
  • Loading branch information
Sarah Buchanan committed Mar 21, 2017
1 parent fc91066 commit f529705
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

@Override
Expand All @@ -13,5 +17,34 @@ protected void onCreate(Bundle savedInstanceState) {

TextView textView = (TextView)this.findViewById(R.id.text_view_title);
textView.setText(R.string.products_title);

ArrayList<String> candy_list = new ArrayList<String>();

candy_list.add("Tropical Wave");
candy_list.add("Berry Bouncer");
candy_list.add("Grape Gummer");
candy_list.add("Apple of My Eye");
candy_list.add("Much Minty");
candy_list.add("So Fresh");
candy_list.add("Sassy Sandwich Cookie");
candy_list.add("Uni-pop");
candy_list.add("Strawberry Surprise");
candy_list.add("Wish Upon a Star");
candy_list.add("Planetary Pops");
candy_list.add("Watermelon Like Whoa");
candy_list.add("Twist 'n' Shout");
candy_list.add("Beary Squad Goals");
candy_list.add("ROYGBIV Spinner");

ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,
R.layout.list_item_candy,
R.id.text_view_candy,
candy_list
);

ListView listView = (ListView)this.findViewById(R.id.list_view_candy);

listView.setAdapter(adapter);
}
}
7 changes: 6 additions & 1 deletion CandyCoded/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="@dimen/activity_padding"
android:text="Temporary Text"
android:text="@string/products_title"
android:textSize="@dimen/title_size" />

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_view_candy"/>

</LinearLayout>
7 changes: 7 additions & 0 deletions CandyCoded/app/src/main/res/layout/list_item_candy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/text_view_candy">

</TextView>

0 comments on commit f529705

Please sign in to comment.