diff --git a/android-pro-listview/AndroidManifest.xml b/android-pro-listview/AndroidManifest.xml new file mode 100644 index 0000000..66cb763 --- /dev/null +++ b/android-pro-listview/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/android-pro-listview/ic_launcher-web.png b/android-pro-listview/ic_launcher-web.png new file mode 100644 index 0000000..a18cbb4 Binary files /dev/null and b/android-pro-listview/ic_launcher-web.png differ diff --git a/android-pro-listview/res/drawable-hdpi/action_help.png b/android-pro-listview/res/drawable-hdpi/action_help.png new file mode 100644 index 0000000..459bed7 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/action_help.png differ diff --git a/android-pro-listview/res/drawable-hdpi/action_help_32.png b/android-pro-listview/res/drawable-hdpi/action_help_32.png new file mode 100644 index 0000000..72edd5a Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/action_help_32.png differ diff --git a/android-pro-listview/res/drawable-hdpi/action_search.png b/android-pro-listview/res/drawable-hdpi/action_search.png new file mode 100644 index 0000000..e6b7045 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/action_search.png differ diff --git a/android-pro-listview/res/drawable-hdpi/action_search_32.png b/android-pro-listview/res/drawable-hdpi/action_search_32.png new file mode 100644 index 0000000..3aa6440 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/action_search_32.png differ diff --git a/android-pro-listview/res/drawable-hdpi/collections_cloud.png b/android-pro-listview/res/drawable-hdpi/collections_cloud.png new file mode 100644 index 0000000..e3d0633 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/collections_cloud.png differ diff --git a/android-pro-listview/res/drawable-hdpi/collections_cloud_32.png b/android-pro-listview/res/drawable-hdpi/collections_cloud_32.png new file mode 100644 index 0000000..3dcb299 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/collections_cloud_32.png differ diff --git a/android-pro-listview/res/drawable-hdpi/content_save.png b/android-pro-listview/res/drawable-hdpi/content_save.png new file mode 100644 index 0000000..07c2817 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/content_save.png differ diff --git a/android-pro-listview/res/drawable-hdpi/ic_launcher.png b/android-pro-listview/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..288b665 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/ic_launcher.png differ diff --git a/android-pro-listview/res/drawable-hdpi/location_place.png b/android-pro-listview/res/drawable-hdpi/location_place.png new file mode 100644 index 0000000..459590a Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/location_place.png differ diff --git a/android-pro-listview/res/drawable-hdpi/rectangle.xml b/android-pro-listview/res/drawable-hdpi/rectangle.xml new file mode 100644 index 0000000..48d9582 --- /dev/null +++ b/android-pro-listview/res/drawable-hdpi/rectangle.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/android-pro-listview/res/drawable-hdpi/social_share.png b/android-pro-listview/res/drawable-hdpi/social_share.png new file mode 100644 index 0000000..47ae186 Binary files /dev/null and b/android-pro-listview/res/drawable-hdpi/social_share.png differ diff --git a/android-pro-listview/res/layout/activity_main.xml b/android-pro-listview/res/layout/activity_main.xml new file mode 100644 index 0000000..6adebd9 --- /dev/null +++ b/android-pro-listview/res/layout/activity_main.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/android-pro-listview/res/layout/group_header_item.xml b/android-pro-listview/res/layout/group_header_item.xml new file mode 100644 index 0000000..345b61f --- /dev/null +++ b/android-pro-listview/res/layout/group_header_item.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/android-pro-listview/res/layout/target_item.xml b/android-pro-listview/res/layout/target_item.xml new file mode 100644 index 0000000..89ed93b --- /dev/null +++ b/android-pro-listview/res/layout/target_item.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + diff --git a/android-pro-listview/res/menu/main.xml b/android-pro-listview/res/menu/main.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/android-pro-listview/res/menu/main.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/android-pro-listview/res/values/dimens.xml b/android-pro-listview/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/android-pro-listview/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/android-pro-listview/res/values/strings.xml b/android-pro-listview/res/values/strings.xml new file mode 100644 index 0000000..768f7cf --- /dev/null +++ b/android-pro-listview/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + Advanced ListView + Settings + Hello world! + + diff --git a/android-pro-listview/res/values/styles.xml b/android-pro-listview/res/values/styles.xml new file mode 100644 index 0000000..6ce89c7 --- /dev/null +++ b/android-pro-listview/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/android-pro-listview/src/com/hmkcode/android/Item.java b/android-pro-listview/src/com/hmkcode/android/Item.java new file mode 100644 index 0000000..b1334d1 --- /dev/null +++ b/android-pro-listview/src/com/hmkcode/android/Item.java @@ -0,0 +1,48 @@ +package com.hmkcode.android; + +public class Item { + + private int icon; + private String title; + private String counter; + + private boolean isGroupHeader = false; + + public Item(String title) { + this(-1,title,null); + isGroupHeader = true; + } + public Item(int icon, String title, String counter) { + super(); + this.icon = icon; + this.title = title; + this.counter = counter; + } + public int getIcon() { + return icon; + } + public void setIcon(int icon) { + this.icon = icon; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getCounter() { + return counter; + } + public void setCounter(String counter) { + this.counter = counter; + } + public boolean isGroupHeader() { + return isGroupHeader; + } + public void setGroupHeader(boolean isGroupHeader) { + this.isGroupHeader = isGroupHeader; + } + + + +} diff --git a/android-pro-listview/src/com/hmkcode/android/MainActivity.java b/android-pro-listview/src/com/hmkcode/android/MainActivity.java new file mode 100644 index 0000000..975ad4f --- /dev/null +++ b/android-pro-listview/src/com/hmkcode/android/MainActivity.java @@ -0,0 +1,41 @@ +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("Group Title")); + items.add(new Item(R.drawable.action_help_32,"Menu Item 1","1")); + items.add(new Item(R.drawable.action_search_32,"Menu Item 2","2")); + items.add(new Item(R.drawable.collections_cloud_32,"Menu Item 3","12")); + + return items; + } + +} diff --git a/android-pro-listview/src/com/hmkcode/android/MyAdapter.java b/android-pro-listview/src/com/hmkcode/android/MyAdapter.java new file mode 100644 index 0000000..e77ba37 --- /dev/null +++ b/android-pro-listview/src/com/hmkcode/android/MyAdapter.java @@ -0,0 +1,60 @@ +package com.hmkcode.android; + +import java.util.ArrayList; + +import com.hmkcode.android.R; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +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.target_item, 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 = null; + if(!itemsArrayList.get(position).isGroupHeader()){ + rowView = inflater.inflate(R.layout.target_item, parent, false); + + // 3. Get icon,title & counter views from the rowView + ImageView imgView = (ImageView) rowView.findViewById(R.id.item_icon); + TextView titleView = (TextView) rowView.findViewById(R.id.item_title); + TextView counterView = (TextView) rowView.findViewById(R.id.item_counter); + + // 4. Set the text for textView + imgView.setImageResource(itemsArrayList.get(position).getIcon()); + titleView.setText(itemsArrayList.get(position).getTitle()); + counterView.setText(itemsArrayList.get(position).getCounter()); + } + else{ + rowView = inflater.inflate(R.layout.group_header_item, parent, false); + TextView titleView = (TextView) rowView.findViewById(R.id.header); + titleView.setText(itemsArrayList.get(position).getTitle()); + + } + + // 5. retrn rowView + return rowView; + } +}