オープンソースフレームワークignition[二]

3556 ワード

1新しいandroidプロジェクトをlibraryとしてignition-coreにインポート
ignition-support guavaインポートが欠けています
2 androidプロジェクトadd ignition-coreをlibraryとして新規作成
同様にguavaをインポート
InfinityAdapterの変更

public InfinityAdapter(Activity activity, AbsListView gridView) {
        super(activity, gridView,R.layout.loading_item);
    }

GridView Activityの追加

package com.github.ignition.samples.core;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.GridView;

import com.github.ignition.core.tasks.IgnitedAsyncTask;

public class GridViewActivity extends Activity implements OnScrollListener {
	private static final int PAGE_SIZE = 10;

	private InfinityAdapter adapter;

	private GridView mGrid;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.grid_1);
        mGrid = (GridView) findViewById(R.id.myGrid);
		adapter = new InfinityAdapter(this, mGrid);
		
		mGrid.setAdapter(adapter);
		mGrid.setOnScrollListener(this);

		loadNextPage();
	}

	private void loadNextPage() {
		adapter.setIsLoadingData(true);
		IgnitedAsyncTask<EndlessListActivity, Void, Void, Void> task = new IgnitedAsyncTask<EndlessListActivity, Void, Void, Void>() {
			@Override
			public Void run(Void... params) throws Exception {
				SystemClock.sleep(1000);
				int offset = adapter.getCount();
				for (int i = 1; i <= PAGE_SIZE; i++) {
					adapter.getData().add(i + offset);
				}
				return null;
			}

			@Override
			public boolean onTaskCompleted(Void result) {
				adapter.setIsLoadingData(false);
				adapter.notifyDataSetChanged();
				return true;
			}
		};
		task.execute();
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		if (adapter.shouldRequestNextPage(firstVisibleItem, visibleItemCount,
				totalItemCount)) {
			loadNextPage();
		}
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
	}
}


grid_を追加1.xml

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myGrid"
	android:layout_width="match_parent" 
	android:layout_height="match_parent"
    android:padding="10dp"
    android:verticalSpacing="10dp"
    
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:columnWidth="60dp"
    android:stretchMode="columnWidth"
    
    android:gravity="center"
    />

SampleListActivityの変更
ふえる

adapter.add(new Sample("GridViewAdapter", GridViewActivity.class));

AndroidManifest.xml増加

 <activity android:name=".GridViewActivity" />