@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.hmkcode.android"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-sdk
|
||||||
|
android:minSdkVersion="8"
|
||||||
|
android:targetSdkVersion="17" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/AppTheme" >
|
||||||
|
<activity
|
||||||
|
android:name="com.hmkcode.android.MainActivity"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#5490CC"></solid>
|
||||||
|
<corners android:radius="8px"></corners>
|
||||||
|
<stroke android:width="2dp" android:color="#A4C2E0"></stroke>
|
||||||
|
</shape>
|
||||||
|
After Width: | Height: | Size: 1.7 KiB |
@ -0,0 +1,14 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
tools:context=".MainActivity"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/listview"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
<?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="48dp"
|
||||||
|
|
||||||
|
android:background="#F3F3F3">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- title -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/header"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textSize="16dp"
|
||||||
|
android:layout_marginLeft="12dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:layout_alignParentBottom="true" />
|
||||||
|
|
||||||
|
<!-- divider -->
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginBottom="1dp"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:background="#DADADC" ></View>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
<?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="48dp"
|
||||||
|
android:background="#F3F3F3">
|
||||||
|
|
||||||
|
<!-- icon -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/item_icon"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:src="@drawable/action_help"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- title -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/item_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_toRightOf="@+id/item_icon"
|
||||||
|
android:layout_alignBaseline="@+id/item_counter"
|
||||||
|
android:textSize="18dp" />
|
||||||
|
|
||||||
|
<!-- counter -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/item_counter"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@drawable/rectangle"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/action_settings"/>
|
||||||
|
|
||||||
|
</menu>
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
|
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||||
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
|
|
||||||
|
</resources>
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="app_name">Advanced ListView</string>
|
||||||
|
<string name="action_settings">Settings</string>
|
||||||
|
<string name="hello_world">Hello world!</string>
|
||||||
|
|
||||||
|
</resources>
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Base application theme, dependent on API level. This theme is replaced
|
||||||
|
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||||
|
-->
|
||||||
|
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||||
|
<!--
|
||||||
|
Theme customizations available in newer API levels can go in
|
||||||
|
res/values-vXX/styles.xml, while customizations related to
|
||||||
|
backward-compatibility can go here.
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Application theme. -->
|
||||||
|
<style name="AppTheme" parent="AppBaseTheme">
|
||||||
|
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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<Item> generateData(){
|
||||||
|
ArrayList<Item> items = new ArrayList<Item>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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<Item> {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private final ArrayList<Item> itemsArrayList;
|
||||||
|
|
||||||
|
public MyAdapter(Context context, ArrayList<Item> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||