Skip to content

Commit 7a123f5

Browse files
committed
change layout
1 parent b837e86 commit 7a123f5

File tree

5 files changed

+154
-94
lines changed

5 files changed

+154
-94
lines changed

res/layout/main.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="fill_parent"
44
android:layout_height="fill_parent"
5-
android:orientation="vertical" >
5+
android:orientation="vertical" android:background="#f0f0f0">
66

77
<TextView
88
android:layout_width="fill_parent"
99
android:layout_height="wrap_content"
1010
android:text="@string/hello" />
1111

12+
<me.maxwin.view.XListView
13+
android:id="@+id/xListView"
14+
android:layout_width="fill_parent"
15+
android:layout_height="fill_parent" android:cacheColorHint="#00000000">
16+
</me.maxwin.view.XListView>
17+
1218
</LinearLayout>

res/layout/xlistview_footer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:layout_height="wrap_content" >
55

66
<RelativeLayout
7-
android:id="@+id/xlistview_footer"
7+
android:id="@+id/xlistview_footer_content"
88
android:layout_width="fill_parent"
99
android:layout_height="wrap_content"
1010
android:padding="10dp" >

res/layout/xlistview_header.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="fill_parent"
44
android:layout_height="wrap_content"
5-
android:background="#ff0000"
65
android:gravity="bottom" >
76

87
<RelativeLayout
9-
android:id="@+id/xlistview_header"
8+
android:id="@+id/xlistview_header_content"
109
android:layout_width="fill_parent"
1110
android:layout_height="60dp" >
1211

1312
<LinearLayout
14-
android:id="@+id/xlistview_header_content"
1513
android:layout_width="wrap_content"
1614
android:layout_height="wrap_content"
1715
android:layout_centerInParent="true"
1816
android:gravity="center"
19-
android:orientation="vertical" >
17+
android:orientation="vertical" android:id="@+id/xlistview_header_text">
2018

2119
<TextView
2220
android:id="@+id/xlistview_header_hint_textview"
@@ -44,10 +42,10 @@
4442
</LinearLayout>
4543

4644
<ImageView
47-
android:id="@drawable/xlistview_arrow"
45+
android:id="@+id/xlistview_header_arrow"
4846
android:layout_width="wrap_content"
4947
android:layout_height="wrap_content"
50-
android:layout_alignLeft="@id/xlistview_header_content"
48+
android:layout_alignLeft="@id/xlistview_header_text"
5149
android:layout_centerVertical="true"
5250
android:layout_marginLeft="-35dp"
5351
android:src="@drawable/xlistview_arrow" />
@@ -56,7 +54,7 @@
5654
android:id="@+id/xlistview_header_progressbar"
5755
android:layout_width="30dp"
5856
android:layout_height="30dp"
59-
android:layout_alignLeft="@id/xlistview_header_content"
57+
android:layout_alignLeft="@id/xlistview_header_text"
6058
android:layout_centerVertical="true"
6159
android:layout_marginLeft="-40dp"
6260
android:visibility="invisible" />

src/me/maxwin/XListViewActivity.java

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,70 @@
11
package me.maxwin;
22

3+
import java.util.ArrayList;
4+
5+
import me.maxwin.view.XListView;
6+
import me.maxwin.view.XListView.IXListViewListener;
37
import android.app.Activity;
48
import android.os.Bundle;
9+
import android.os.Handler;
10+
import android.widget.ArrayAdapter;
11+
12+
public class XListViewActivity extends Activity implements IXListViewListener {
13+
private XListView mListView;
14+
private ArrayAdapter<String> mAdapter;
15+
private ArrayList<String> items = new ArrayList<String>();
16+
private Handler mHandler;
17+
private int start = 0;
18+
private static int refreshCnt = 0;
19+
/** Called when the activity is first created. */
20+
@Override
21+
public void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
setContentView(R.layout.main);
24+
geneItems();
25+
mListView = (XListView) findViewById(R.id.xListView);
26+
mListView.setPullLoadEnable(true);
27+
mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, items);
28+
mListView.setAdapter(mAdapter);
29+
mListView.setXListViewListener(this);
30+
mHandler = new Handler();
31+
}
32+
33+
private void geneItems() {
34+
for (int i = 0; i != 20; ++i) {
35+
items.add("refresh cnt " + (++start));
36+
}
37+
}
38+
39+
private void onLoad() {
40+
mListView.stopRefresh();
41+
mListView.stopLoadMore();
42+
}
43+
44+
@Override
45+
public void onRefresh() {
46+
mHandler.postDelayed(new Runnable() {
47+
@Override
48+
public void run() {
49+
start = ++refreshCnt;
50+
items.clear();
51+
geneItems();
52+
mAdapter.notifyDataSetChanged();
53+
onLoad();
54+
}
55+
}, 3000);
56+
}
57+
58+
@Override
59+
public void onLoadMore() {
60+
mHandler.postDelayed(new Runnable() {
61+
@Override
62+
public void run() {
63+
geneItems();
64+
mAdapter.notifyDataSetChanged();
65+
onLoad();
66+
}
67+
}, 3000);
68+
}
569

6-
public class XListViewActivity extends Activity {
7-
/** Called when the activity is first created. */
8-
@Override
9-
public void onCreate(Bundle savedInstanceState) {
10-
super.onCreate(savedInstanceState);
11-
setContentView(R.layout.main);
12-
}
1370
}

0 commit comments

Comments
 (0)