└── ListView
├── .gitignore
├── .project
├── AndroidManifest.xml
├── default.properties
├── proguard.cfg
├── res
├── drawable-hdpi
│ └── icon.png
├── drawable-ldpi
│ └── icon.png
├── drawable-mdpi
│ └── icon.png
├── layout
│ ├── item.xml
│ └── main.xml
└── values
│ └── strings.xml
└── src
└── com
└── stylingandroid
└── listview
├── CustomAdapter.java
└── ListViewActivity.java
/ListView/.gitignore:
--------------------------------------------------------------------------------
1 | /gen
2 | /.classpath
3 |
--------------------------------------------------------------------------------
/ListView/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ListView
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/ListView/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ListView/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-10
12 |
--------------------------------------------------------------------------------
/ListView/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/ListView/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StylingAndroid/ListView/ec23aca420f37588a27cb3d98b6ce3a9766bdd4f/ListView/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/ListView/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StylingAndroid/ListView/ec23aca420f37588a27cb3d98b6ce3a9766bdd4f/ListView/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/ListView/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StylingAndroid/ListView/ec23aca420f37588a27cb3d98b6ce3a9766bdd4f/ListView/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/ListView/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/ListView/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/ListView/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, ListViewActivity!
4 | ListView
5 |
6 |
--------------------------------------------------------------------------------
/ListView/src/com/stylingandroid/listview/CustomAdapter.java:
--------------------------------------------------------------------------------
1 | package com.stylingandroid.listview;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import android.content.Context;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 | import android.view.ViewGroup;
12 | import android.widget.BaseAdapter;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | public class CustomAdapter extends BaseAdapter
18 | {
19 | private final Context context;
20 | private final List items;
21 | private final Map> cache = new HashMap>();
22 |
23 | public CustomAdapter( Context context, List items )
24 | {
25 | this.context = context;
26 | this.items = items;
27 | }
28 |
29 | @Override
30 | public int getCount()
31 | {
32 | return items.size();
33 | }
34 |
35 | @Override
36 | public Object getItem( int position )
37 | {
38 | return items.get( position );
39 | }
40 |
41 | @Override
42 | public long getItemId( int position )
43 | {
44 | return getItem( position ).hashCode();
45 | }
46 |
47 | @Override
48 | public View getView( int position, View convertView, ViewGroup parent )
49 | {
50 | View v = convertView;
51 | TextView tv;
52 | ImageView iv;
53 | if ( v == null )
54 | {
55 | LayoutInflater inflater = (LayoutInflater) context
56 | .getSystemService( Context.LAYOUT_INFLATER_SERVICE );
57 | v = inflater.inflate( R.layout.item, parent, false );
58 | }
59 | Map itemMap = cache.get( v );
60 | if( itemMap == null )
61 | {
62 | itemMap = new HashMap();
63 | tv = (TextView) v.findViewById( android.R.id.text1 );
64 | iv = (ImageView) v.findViewById( R.id.imageView );
65 | itemMap.put( android.R.id.text1, tv );
66 | itemMap.put(R.id.imageView, iv );
67 | cache.put( v, itemMap );
68 | }
69 | else
70 | {
71 | tv = (TextView)itemMap.get( android.R.id.text1 );
72 | iv = (ImageView)itemMap.get( R.id.imageView );
73 | }
74 | final String item = (String) getItem( position );
75 | tv.setText( item );
76 | iv.setOnClickListener( new OnClickListener()
77 | {
78 |
79 | @Override
80 | public void onClick( View v )
81 | {
82 | Toast.makeText( context,
83 | String.format( "Image clicked: %s", item ),
84 | Toast.LENGTH_SHORT ).show();
85 | }
86 | } );
87 | return v;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/ListView/src/com/stylingandroid/listview/ListViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.stylingandroid.listview;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.app.Activity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.widget.AdapterView;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 | import android.widget.AdapterView.OnItemClickListener;
14 |
15 | public class ListViewActivity extends Activity
16 | {
17 | @Override
18 | public void onCreate( Bundle savedInstanceState )
19 | {
20 | super.onCreate( savedInstanceState );
21 | setContentView( R.layout.main );
22 |
23 | List data = new ArrayList();
24 | for ( int i = 1; i <= 10; i++ )
25 | {
26 | data.add( String.format( "Item %d", i ) );
27 | }
28 |
29 | CustomAdapter adapter = new CustomAdapter( this, data );
30 |
31 | ListView listView = (ListView)findViewById( android.R.id.list );
32 | listView.setAdapter( adapter );
33 |
34 | listView.setOnItemClickListener( new OnItemClickListener()
35 | {
36 |
37 | @Override
38 | public void onItemClick( AdapterView> listView, View view,
39 | int pos, long id )
40 | {
41 | TextView textView = (TextView) view.findViewById( android.R.id.text1 );
42 | toast( (String) textView.getText() );
43 | }
44 | } );
45 |
46 | }
47 |
48 | private void toast( String text )
49 | {
50 | Toast.makeText( ListViewActivity.this,
51 | String.format( "Item clicked: %s", text ), Toast.LENGTH_SHORT )
52 | .show();
53 | }
54 | }
--------------------------------------------------------------------------------