Android 滑动加载数据(二)

2014-11-24 03:24:53 · 作者: · 浏览: 7
Create(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
LinearLayout searchLayout = new LinearLayout( this );
searchLayout.setOrientation(LinearLayout.HORIZONTAL);

Button textView = new Button( this );
textView.setText( " 加载中... " );
textView.setGravity(Gravity.CENTER_VERTICAL);
searchLayout.addView(textView, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
searchLayout.setGravity(Gravity.CENTER);
LinearLayout loadingLayout = new LinearLayout( this );
loadingLayout.addView(searchLayout, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
loadingLayout.setGravity(Gravity.CENTER);
getListView().addFooterView(loadingLayout);
textView.setOnClickListener( new Button.OnClickListener()
{ @Override
public void onClick(View v)
{
adapter.count += 10 ;
adapter.notifyDataSetChanged();
}
});


setListAdapter(adapter);
// getListView().setOnScrollListener(this);
}

/* public void onScroll(AbsListView view,
int firstVisible, int visibleCount, int totalCount) {

boolean loadMore =
firstVisible + visibleCount >= totalCount;

if(loadMore) {
adapter.count += visibleCount;
adapter.notifyDataSetChanged();
}
} */

public void onScrollStateChanged(AbsListView v, int s) { }

class Aleph0 extends BaseAdapter {
int count = 40 ; /* starting amount */

public int getCount() { return count; }
public Object getItem( int pos) { return pos; }
public long getItemId( int pos) { return pos; }

public View getView( int pos, View v, ViewGroup p) {
TextView view = new TextView(EndLessActivity. this );
view.setText( " entry " + pos);
return view;
}
}
}