Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit c36cc4d

Browse files
committed
Updated samples with list selection on the ListView and android:listSelector implemented - to show that SGV doesn’t support this yet.
1 parent bf256cd commit c36cc4d

7 files changed

Lines changed: 33 additions & 5 deletions

File tree

sample/src/main/java/com/etsy/android/sample/ListViewActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import java.util.List;
1313

14-
public class ListViewActivity extends Activity {
14+
public class ListViewActivity extends Activity implements AdapterView.OnItemClickListener {
1515

1616
@Override
1717
protected void onCreate(Bundle savedInstanceState) {
@@ -36,11 +36,16 @@ protected void onCreate(Bundle savedInstanceState) {
3636

3737
final SampleAdapter adapter = new SampleAdapter(this, R.id.txt_line1);
3838
listView.setAdapter(adapter);
39+
listView.setOnItemClickListener(this);
3940

4041
final List<String> sampleData = SampleData.generateSampleData();
4142
for (String data : sampleData) {
4243
adapter.add(data);
4344
}
4445
}
4546

47+
@Override
48+
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
49+
Toast.makeText(this, "Item Clicked: " + position, Toast.LENGTH_SHORT).show();
50+
}
4651
}

sample/src/main/java/com/etsy/android/sample/StaggeredGridActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ private void onLoadMoreItems() {
107107

108108
@Override
109109
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
110-
Toast.makeText(getApplicationContext(), "Clicked: " + position, Toast.LENGTH_LONG).show();
110+
Toast.makeText(this, "Item Clicked: " + position, Toast.LENGTH_SHORT).show();
111111
}
112112
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<!-- shapes defined for Android 2.3 drawable issues -->
6+
<item android:state_pressed="true" >
7+
<shape android:shape="rectangle">
8+
 <solid android:color="@color/list_item_pressed" />
9+
</shape>
10+
</item>
11+
12+
<!-- default -->
13+
<item>
14+
<shape android:shape="rectangle">
15+
 <solid android:color="@android:color/transparent" />
16+
</shape>
17+
</item>
18+
19+
</selector>

sample/src/main/res/layout/activity_list_view.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<ListView
66
android:id="@+id/list_view"
77
android:layout_width="match_parent"
8-
android:layout_height="match_parent" />
8+
android:layout_height="match_parent"
9+
android:listSelector="@drawable/list_item_selector"
10+
android:drawSelectorOnTop="true" />
911

1012
</FrameLayout>

sample/src/main/res/layout/activity_sgv.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
android:layout_height="match_parent"
1010
app:item_margin="8dp"
1111
app:column_count_portrait="2"
12-
app:column_count_landscape="3" />
12+
app:column_count_landscape="3"/>
1313

1414
</FrameLayout>

sample/src/main/res/layout/list_item_sample.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
android:orientation="horizontal"
55
android:id="@+id/panel_content"
66
android:layout_width="match_parent"
7-
android:layout_height="wrap_content">
7+
android:layout_height="wrap_content"
8+
android:descendantFocusability="blocksDescendants">
89

910
<com.etsy.android.grid.util.DynamicHeightTextView
1011
android:id="@+id/txt_line1"

sample/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
<color name="blue">#ff82e0ff</color>
77
<color name="yellow">#fffffbae</color>
88
<color name="red">#fff10800</color>
9+
<color name="list_item_pressed">#1A000000</color>
910
</resources>

0 commit comments

Comments
 (0)