diff --git a/android-custom-listview/AndroidManifest.xml b/android-custom-listview/AndroidManifest.xml new file mode 100644 index 0000000..66cb763 --- /dev/null +++ b/android-custom-listview/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/android-custom-listview/ic_launcher-web.png b/android-custom-listview/ic_launcher-web.png new file mode 100644 index 0000000..a18cbb4 Binary files /dev/null and b/android-custom-listview/ic_launcher-web.png differ diff --git a/android-custom-listview/res/drawable-hdpi/ic_launcher.png b/android-custom-listview/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..288b665 Binary files /dev/null and b/android-custom-listview/res/drawable-hdpi/ic_launcher.png differ diff --git a/android-custom-listview/res/layout/activity_main.xml b/android-custom-listview/res/layout/activity_main.xml new file mode 100644 index 0000000..6adebd9 --- /dev/null +++ b/android-custom-listview/res/layout/activity_main.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/android-custom-listview/res/layout/row.xml b/android-custom-listview/res/layout/row.xml new file mode 100644 index 0000000..ddfaeca --- /dev/null +++ b/android-custom-listview/res/layout/row.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/android-custom-listview/res/menu/main.xml b/android-custom-listview/res/menu/main.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/android-custom-listview/res/menu/main.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/android-custom-listview/res/values/dimens.xml b/android-custom-listview/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/android-custom-listview/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/android-custom-listview/res/values/strings.xml b/android-custom-listview/res/values/strings.xml new file mode 100644 index 0000000..543e12c --- /dev/null +++ b/android-custom-listview/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + App + Settings + Hello world! + + diff --git a/android-custom-listview/res/values/styles.xml b/android-custom-listview/res/values/styles.xml new file mode 100644 index 0000000..0a4178a --- /dev/null +++ b/android-custom-listview/res/values/styles.xml @@ -0,0 +1,179 @@ + + + + + + + + + + #FFFFFF + #FFFF00 + #FF00FF + #FF0000 + #C0C0C0 + #808080 + #808000 + #800080 + #800000 + #00FFFF + #00FF00 + #008080 + #008000 + #0000FF + #000080 + #000000 + + + #FFFFFF + #FFFFF0 + #FFFFE0 + #FFFF00 + #FFFAFA + #FFFAF0 + #FFFACD + #FFF8DC + #FFF5EE + #FFF0F5 + #FFEFD5 + #FFEBCD + #FFE4E1 + #FFE4C4 + #FFE4B5 + #FFDEAD + #FFDAB9 + #FFD700 + #FFC0CB + #FFB6C1 + #FFA500 + #FFA07A + #FF8C00 + #FF7F50 + #FF69B4 + #FF6347 + #FF4500 + #FF1493 + #FF00FF + #FF00FF + #FF0000 + #FDF5E6 + #FAFAD2 + #FAF0E6 + #FAEBD7 + #FA8072 + #F8F8FF + #F5FFFA + #F5F5F5 + #F5F5DC + #F5DEB3 + #F4A460 + #F0FFFF + #F0FFF0 + #F0F8FF + #F0E68C + #F08080 + #EEE8AA + #EE82EE + #E9967A + #E6E6FA + #E0FFFF + #DEB887 + #DDA0DD + #DCDCDC + #DC143C + #DB7093 + #DAA520 + #DA70D6 + #D8BFD8 + #D3D3D3 + #D2B48C + #D2691E + #CD853F + #CD5C5C + #C71585 + #C0C0C0 + #BDB76B + #BC8F8F + #BA55D3 + #B8860B + #B22222 + #B0E0E6 + #B0C4DE + #AFEEEE + #ADFF2F + #ADD8E6 + #A9A9A9 + #A52A2A + #A0522D + #9ACD32 + #9932CC + #98FB98 + #9400D3 + #9370DB + #90EE90 + #8FBC8F + #8B4513 + #8B008B + #8B0000 + #8A2BE2 + #87CEFA + #87CEEB + #808080 + #808000 + #800080 + #800000 + #7FFFD4 + #7FFF00 + #7CFC00 + #7B68EE + #778899 + #708090 + #6B8E23 + #6A5ACD + #696969 + #66CDAA + #6495ED + #5F9EA0 + #556B2F + #4B0082 + #48D1CC + #483D8B + #4682B4 + #4169E1 + #40E0D0 + #3CB371 + #32CD32 + #2F4F4F + #2E8B57 + #228B22 + #20B2AA + #1E90FF + #191970 + #00FFFF + #00FFFF + #00FF7F + #00FF00 + #00FA9A + #00CED1 + #00BFFF + #008B8B + #008080 + #008000 + #006400 + #0000FF + #0000CD + #00008B + #000080 + #000000 + \ No newline at end of file diff --git a/android-custom-listview/src/com/hmkcode/android/Item.java b/android-custom-listview/src/com/hmkcode/android/Item.java new file mode 100644 index 0000000..1231845 --- /dev/null +++ b/android-custom-listview/src/com/hmkcode/android/Item.java @@ -0,0 +1,31 @@ +package com.hmkcode.android; + +public class Item { + + private String title; + private String description; + + + public Item(String title, String description) { + super(); + this.title = title; + this.description = description; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + + + + +} diff --git a/android-custom-listview/src/com/hmkcode/android/MainActivity.java b/android-custom-listview/src/com/hmkcode/android/MainActivity.java new file mode 100644 index 0000000..78bf3a2 --- /dev/null +++ b/android-custom-listview/src/com/hmkcode/android/MainActivity.java @@ -0,0 +1,40 @@ +package com.hmkcode.android; + +import java.util.ArrayList; + +import android.app.Activity; +import android.app.ListActivity; +import android.os.Bundle; +import android.widget.ListView; + +public class MainActivity extends ListActivity { + + + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // if extending Activity + //setContentView(R.layout.activity_main); + + // 1. pass context and data to the custom adapter + MyAdapter adapter = new MyAdapter(this, generateData()); + + // if extending Activity 2. Get ListView from activity_main.xml + //ListView listView = (ListView) findViewById(R.id.listview); + + // 3. setListAdapter + //listView.setAdapter(adapter); if extending Activity + setListAdapter(adapter); + } + + + private ArrayList generateData(){ + ArrayList items = new ArrayList(); + items.add(new Item("Item 1","First Item on the list")); + items.add(new Item("Item 2","Second Item on the list")); + items.add(new Item("Item 3","Third Item on the list")); + + return items; + } + +} diff --git a/android-custom-listview/src/com/hmkcode/android/MyAdapter.java b/android-custom-listview/src/com/hmkcode/android/MyAdapter.java new file mode 100644 index 0000000..0ca6293 --- /dev/null +++ b/android-custom-listview/src/com/hmkcode/android/MyAdapter.java @@ -0,0 +1,46 @@ +package com.hmkcode.android; + +import java.util.ArrayList; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +public class MyAdapter extends ArrayAdapter { + + private final Context context; + private final ArrayList itemsArrayList; + + public MyAdapter(Context context, ArrayList itemsArrayList) { + + super(context, R.layout.row, itemsArrayList); + + this.context = context; + this.itemsArrayList = itemsArrayList; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + // 1. Create inflater + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + // 2. Get rowView from inflater + View rowView = inflater.inflate(R.layout.row, parent, false); + + // 3. Get the two text view from the rowView + TextView labelView = (TextView) rowView.findViewById(R.id.label); + TextView valueView = (TextView) rowView.findViewById(R.id.value); + + // 4. Set the text for textView + labelView.setText(itemsArrayList.get(position).getTitle()); + valueView.setText(itemsArrayList.get(position).getDescription()); + + // 5. retrn rowView + return rowView; + } +}