Skip to content

Commit f0457ff

Browse files
committed
Recylerview updated
1 parent a874401 commit f0457ff

File tree

14 files changed

+44
-55
lines changed

14 files changed

+44
-55
lines changed

com.vogella.android.recyclerview/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:allowBackup="true"
1313
android:icon="@drawable/ic_launcher"
1414
android:label="@string/app_name"
15-
android:theme="@style/AppTheme" >
15+
android:theme="@android:style/Theme.Material.Light" >
1616
<activity
1717
android:name=".MainActivity"
1818
android:label="@string/app_name" >

com.vogella.android.recyclerview/res/layout/activity_main.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,15 @@
1212
android:layout_height="match_parent"
1313
android:scrollbars="vertical" />
1414

15+
<ImageView
16+
android:id="@+id/imageView1"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:layout_alignParentBottom="true"
20+
android:layout_alignParentRight="true"
21+
android:layout_marginBottom="12dp"
22+
android:layout_marginRight="12dp"
23+
android:elevation="2dp"
24+
android:src="@drawable/ic_add_circle" />
25+
1526
</RelativeLayout>
Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,7 @@
1-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:layout_width="fill_parent"
3-
android:layout_height="?android:attr/listPreferredItemHeight"
4-
android:padding="6dip" >
5-
6-
<ImageView
7-
android:id="@+id/icon"
8-
android:layout_width="wrap_content"
9-
android:layout_height="fill_parent"
10-
android:layout_alignParentBottom="true"
11-
android:layout_alignParentTop="true"
12-
android:layout_marginRight="6dip"
13-
android:contentDescription="TODO"
14-
android:src="@drawable/ic_launcher" />
15-
16-
<TextView
17-
android:id="@+id/secondLine"
18-
android:layout_width="fill_parent"
19-
android:layout_height="26dip"
20-
android:layout_alignParentBottom="true"
21-
android:layout_alignParentRight="true"
22-
android:layout_toRightOf="@id/icon"
23-
android:ellipsize="marquee"
24-
android:singleLine="true"
25-
android:text="Description"
26-
android:textSize="12sp" />
27-
28-
<TextView
29-
android:id="@+id/firstLine"
30-
android:layout_width="fill_parent"
31-
android:layout_height="wrap_content"
32-
android:layout_above="@id/secondLine"
33-
android:layout_alignParentRight="true"
34-
android:layout_alignParentTop="true"
35-
android:layout_alignWithParentIfMissing="true"
36-
android:layout_toRightOf="@id/icon"
37-
android:gravity="center_vertical"
38-
android:text="Example application"
39-
android:textSize="16sp" />
40-
41-
</RelativeLayout>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/textView1"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:text="Large Text"
7+
android:textAppearance="?android:attr/textAppearanceLarge" />
Lines 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>

com.vogella.android.recyclerview/src/com/vogella/android/recyclerview/MyAdapter.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>
1515
private ArrayList<String> mDataset;
1616

1717
// Provide a reference to the views for each data item
18+
// Complex data items may need more than one view per item, and
19+
// you provide access to all the views for a data item in a view holder
1820
public class ViewHolder extends RecyclerView.ViewHolder {
1921
// each data item is just a string in this case
20-
public TextView bigTextView;
21-
public TextView smallTextView;
22+
public TextView mTextView;
2223

23-
public ViewHolder(TextView big, TextView small) {
24-
super(big);
25-
bigTextView = big;
26-
smallTextView = small;
24+
public ViewHolder(TextView v) {
25+
super(v);
26+
mTextView = v;
2727
}
2828
}
2929

@@ -48,10 +48,10 @@ public MyAdapter(ArrayList<String> myDataset) {
4848
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
4949
int viewType) {
5050
// create a new view
51-
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.rowlayout, parent, false);
52-
TextView bigText = (TextView) v.findViewById(R.id.firstLine);
53-
TextView smallText = (TextView) v.findViewById(R.id.secondLine);
54-
ViewHolder vh = new ViewHolder(bigText, smallText);
51+
TextView v = (TextView) LayoutInflater.from(parent.getContext())
52+
.inflate(R.layout.rowlayout, parent, false);
53+
// set the view's size, margins, paddings and layout parameters
54+
ViewHolder vh = new ViewHolder(v);
5555
return vh;
5656
}
5757

@@ -61,14 +61,14 @@ public void onBindViewHolder(ViewHolder holder, int position) {
6161
// - get element from your dataset at this position
6262
// - replace the contents of the view with that element
6363
final String name = mDataset.get(position);
64-
holder.bigTextView.setText(mDataset.get(position));
65-
holder.bigTextView.setOnClickListener(new OnClickListener() {
64+
holder.mTextView.setText(mDataset.get(position));
65+
holder.mTextView.setOnClickListener(new OnClickListener() {
6666
@Override
6767
public void onClick(View v) {
6868
remove(name);
6969
}
7070
});
71-
holder.smallTextView.setText("Example data");
71+
7272
}
7373

7474
// Return the size of your dataset (invoked by the layout manager)

0 commit comments

Comments
 (0)