forked from Maxwin-z/XListView-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,70 @@ | ||
package me.maxwin; | ||
|
||
import java.util.ArrayList; | ||
|
||
import me.maxwin.view.XListView; | ||
import me.maxwin.view.XListView.IXListViewListener; | ||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.widget.ArrayAdapter; | ||
|
||
public class XListViewActivity extends Activity implements IXListViewListener { | ||
private XListView mListView; | ||
private ArrayAdapter<String> mAdapter; | ||
private ArrayList<String> items = new ArrayList<String>(); | ||
private Handler mHandler; | ||
private int start = 0; | ||
private static int refreshCnt = 0; | ||
/** Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
geneItems(); | ||
mListView = (XListView) findViewById(R.id.xListView); | ||
mListView.setPullLoadEnable(true); | ||
mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, items); | ||
mListView.setAdapter(mAdapter); | ||
mListView.setXListViewListener(this); | ||
mHandler = new Handler(); | ||
} | ||
|
||
private void geneItems() { | ||
for (int i = 0; i != 20; ++i) { | ||
items.add("refresh cnt " + (++start)); | ||
} | ||
} | ||
|
||
private void onLoad() { | ||
mListView.stopRefresh(); | ||
mListView.stopLoadMore(); | ||
} | ||
|
||
@Override | ||
public void onRefresh() { | ||
mHandler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
start = ++refreshCnt; | ||
items.clear(); | ||
geneItems(); | ||
mAdapter.notifyDataSetChanged(); | ||
onLoad(); | ||
} | ||
}, 3000); | ||
} | ||
|
||
@Override | ||
public void onLoadMore() { | ||
mHandler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
geneItems(); | ||
mAdapter.notifyDataSetChanged(); | ||
onLoad(); | ||
} | ||
}, 3000); | ||
} | ||
|
||
public class XListViewActivity extends Activity { | ||
/** Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
} | ||
} |
Oops, something went wrong.