Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a0e6f5

Browse filesBrowse files
JAVATECHIGJAVATECHIG
JAVATECHIG
authored and
JAVATECHIG
committed
Added Customized ListView example
1 parent d237100 commit 0a0e6f5
Copy full SHA for 0a0e6f5

File tree

Expand file treeCollapse file tree

26 files changed

+404
-0
lines changed
Filter options
Expand file treeCollapse file tree

26 files changed

+404
-0
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3+
org.eclipse.jdt.core.compiler.compliance=1.6
4+
org.eclipse.jdt.core.compiler.source=1.6

‎Customizedlist/AndroidManifest.xml

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.customizedlist"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="8"
9+
android:targetSdkVersion="17" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@drawable/ic_launcher"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme" >
16+
<activity
17+
android:name="com.javatechig.customizedlist.MainActivity"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>

‎Customizedlist/ic_launcher-web.png

Copy file name to clipboard
118 KB
Loading
384 KB
Binary file not shown.

‎Customizedlist/proguard-project.txt

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

‎Customizedlist/project.properties

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-17
9.37 KB
Loading
4.73 KB
Loading
Loading
Loading
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true" android:color="@color/text_color_inverse" />
4+
<item android:state_focused="true" android:color="@color/text_color_inverse" />
5+
<item android:color="@color/text_color_default" />
6+
</selector>
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
2+
<item android:drawable="@color/list_row_default_bg" android:state_pressed="false" android:state_selected="false"/>
3+
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
4+
<item android:drawable="@color/list_row_pressed_bg" android:state_pressed="true"/>
5+
<item android:drawable="@color/list_row_selected_bg" android:state_pressed="false" android:state_selected="true"/>
6+
7+
</selector>
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<ListView
8+
android:id="@+id/custom_list"
9+
android:layout_width="fill_parent"
10+
android:layout_height="wrap_content"
11+
android:listSelector="@drawable/list_selector_flatcolor"
12+
android:dividerHeight="1dp" />
13+
14+
</LinearLayout>
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="wrap_content"
5+
android:minHeight="50dp"
6+
android:orientation="horizontal"
7+
android:padding="5dip" >
8+
9+
<TextView
10+
android:id="@+id/title"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text=""
14+
android:textColor="@drawable/list_item_text_selector"
15+
android:textStyle="bold"
16+
android:typeface="sans" />
17+
18+
<TextView
19+
android:id="@+id/reporter"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_below="@id/title"
23+
android:layout_marginTop="5dip"
24+
android:text=""
25+
android:textColor="@drawable/list_item_text_selector"
26+
android:textSize="12sp" />
27+
28+
<TextView
29+
android:id="@+id/date"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:layout_alignBaseline="@+id/reporter"
33+
android:layout_alignBottom="@+id/reporter"
34+
android:layout_alignParentRight="true"
35+
android:text=""
36+
android:textColor="@drawable/list_item_text_selector"
37+
android:textSize="12sp" />
38+
39+
</RelativeLayout>

‎Customizedlist/res/menu/main.xml

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
2+
3+
<item
4+
android:id="@+id/action_settings"
5+
android:orderInCategory="100"
6+
android:showAsAction="never"
7+
android:title="@string/action_settings"/>
8+
9+
</menu>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw600dp devices (e.g. 7" tablets) here.
6+
-->
7+
8+
</resources>
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
6+
-->
7+
<dimen name="activity_horizontal_margin">128dp</dimen>
8+
9+
</resources>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>

‎Customizedlist/res/values/colors.xml

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="text_color_default">#00000C</color>
4+
<color name="text_color_inverse">#FFFFFF</color>
5+
<color name="white">#FFFFFF</color>
6+
<color name="list_row_default_bg">#ffffff</color>
7+
<color name="list_row_pressed_bg">#008cef</color>
8+
<color name="list_row_selected_bg">#86d3f6</color>
9+
</resources>

‎Customizedlist/res/values/dimens.xml

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>

‎Customizedlist/res/values/strings.xml

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">customizedlist</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="hello_world">Hello world!</string>
7+
8+
</resources>

‎Customizedlist/res/values/styles.xml

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.javatechig.customizedlist;
2+
3+
import java.util.ArrayList;
4+
import android.content.Context;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.BaseAdapter;
9+
import android.widget.TextView;
10+
11+
import com.example.customizedlist.R;
12+
13+
public class CustomListAdapter extends BaseAdapter {
14+
15+
private ArrayList<NewsItem> listData;
16+
17+
private LayoutInflater layoutInflater;
18+
19+
public CustomListAdapter(Context context, ArrayList<NewsItem> listData) {
20+
this.listData = listData;
21+
layoutInflater = LayoutInflater.from(context);
22+
}
23+
24+
@Override
25+
public int getCount() {
26+
return listData.size();
27+
}
28+
29+
@Override
30+
public Object getItem(int position) {
31+
return listData.get(position);
32+
}
33+
34+
@Override
35+
public long getItemId(int position) {
36+
return position;
37+
}
38+
39+
public View getView(int position, View convertView, ViewGroup parent) {
40+
ViewHolder holder;
41+
if (convertView == null) {
42+
convertView = layoutInflater.inflate(R.layout.list_row_layout, null);
43+
holder = new ViewHolder();
44+
holder.headlineView = (TextView) convertView.findViewById(R.id.title);
45+
holder.reporterNameView = (TextView) convertView.findViewById(R.id.reporter);
46+
holder.reportedDateView = (TextView) convertView.findViewById(R.id.date);
47+
convertView.setTag(holder);
48+
} else {
49+
holder = (ViewHolder) convertView.getTag();
50+
}
51+
52+
holder.headlineView.setText(listData.get(position).getHeadline());
53+
holder.reporterNameView.setText("By, " + listData.get(position).getReporterName());
54+
holder.reportedDateView.setText(listData.get(position).getDate());
55+
56+
return convertView;
57+
}
58+
59+
static class ViewHolder {
60+
TextView headlineView;
61+
TextView reporterNameView;
62+
TextView reportedDateView;
63+
}
64+
65+
}
+77Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.javatechig.customizedlist;
2+
3+
import java.util.ArrayList;
4+
import android.app.Activity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.AdapterView;
8+
import android.widget.AdapterView.OnItemClickListener;
9+
import android.widget.ListView;
10+
import android.widget.Toast;
11+
12+
import com.example.customizedlist.R;
13+
14+
public class MainActivity extends Activity {
15+
16+
@Override
17+
public void onCreate(Bundle savedInstanceState) {
18+
super.onCreate(savedInstanceState);
19+
setContentView(R.layout.activity_main);
20+
21+
ArrayList<NewsItem> image_details = getListData();
22+
final ListView lv1 = (ListView) findViewById(R.id.custom_list);
23+
lv1.setAdapter(new CustomListAdapter(this, image_details));
24+
lv1.setOnItemClickListener(new OnItemClickListener() {
25+
26+
@Override
27+
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
28+
Object o = lv1.getItemAtPosition(position);
29+
NewsItem newsData = (NewsItem) o;
30+
Toast.makeText(MainActivity.this, "Selected :" + " " + newsData, Toast.LENGTH_LONG).show();
31+
}
32+
33+
});
34+
35+
}
36+
37+
private ArrayList<NewsItem> getListData() {
38+
ArrayList<NewsItem> results = new ArrayList<NewsItem>();
39+
NewsItem newsData = new NewsItem();
40+
newsData.setHeadline("Dance of Democracy");
41+
newsData.setReporterName("Pankaj Gupta");
42+
newsData.setDate("May 26, 2013, 13:35");
43+
results.add(newsData);
44+
45+
newsData = new NewsItem();
46+
newsData.setHeadline("Major Naxal attacks in the past");
47+
newsData.setReporterName("Pankaj Gupta");
48+
newsData.setDate("May 26, 2013, 13:35");
49+
results.add(newsData);
50+
51+
newsData = new NewsItem();
52+
newsData.setHeadline("BCCI suspends Gurunath pending inquiry ");
53+
newsData.setReporterName("Rajiv Chandan");
54+
newsData.setDate("May 26, 2013, 13:35");
55+
results.add(newsData);
56+
57+
newsData = new NewsItem();
58+
newsData.setHeadline("Life convict can`t claim freedom after 14 yrs: SC");
59+
newsData.setReporterName("Pankaj Gupta");
60+
newsData.setDate("May 26, 2013, 13:35");
61+
results.add(newsData);
62+
63+
newsData = new NewsItem();
64+
newsData.setHeadline("Indian Army refuses to share info on soldiers mutilated at LoC");
65+
newsData.setReporterName("Pankaj Gupta");
66+
newsData.setDate("May 26, 2013, 13:35");
67+
results.add(newsData);
68+
69+
newsData = new NewsItem();
70+
newsData.setHeadline("French soldier stabbed; link to Woolwich attack being probed");
71+
newsData.setReporterName("Sudeep Nanda");
72+
newsData.setDate("May 26, 2013, 13:35");
73+
results.add(newsData);
74+
75+
return results;
76+
}
77+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.