use of android.support.v4.app.LoaderManager in project AndroidTraining by mixi-inc.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ローダの管理をするオブジェクト
LoaderManager manager = getSupportLoaderManager();
Bundle argsForLoader = new Bundle();
// ローダを初期化して非同期処理を開始する
manager.initLoader(0, argsForLoader, MainActivity.this);
}
use of android.support.v4.app.LoaderManager in project enroscar by stanfy.
the class LoaderSetTest method shouldWaitFor3Requests.
@Ignore
@Test
public void shouldWaitFor3Requests() throws Throwable {
// enqueue
getWebServer().enqueue(new MockResponse().setBody("R1"));
getWebServer().enqueue(new MockResponse().setBody("R2"));
getWebServer().enqueue(new MockResponse().setBody("R3"));
final URL url = getWebServer().getUrl("/");
final Fragment fragment = createFragment();
final LoaderManager loaderManager = fragment.getLoaderManager();
assertThat(loaderManager).isNotNull();
final CountDownLatch waiter = new CountDownLatch(1);
// describe loader
final LoaderSet set = LoaderSet.build(getApplication()).withManager(loaderManager).withCallbacks(new LoaderSet.SetCallbacksAdapter<ResponseData<String>>() {
@Override
public Loader<ResponseData<String>> onCreateLoader(final int id, final Bundle args) {
return new MyRequestBuilder<String>(getApplication()) {
}.setUrl(url.toString()).setFormat("string").getLoader();
}
}, 1).withCallbacks(new LoaderSet.SetCallbacksAdapter<ResponseData<String>>() {
@Override
public Loader<ResponseData<String>> onCreateLoader(final int id, final Bundle args) {
return new MyRequestBuilder<String>(getApplication()) {
}.setUrl(url.toString()).setFormat("string").getLoader();
}
}, 2, 3).create();
final LoaderSet.LoaderSetCallback callbacks = new LoaderSet.LoaderSetCallback() {
@Override
public void onLoadFinished(final Object[] data) {
Log.i("ChainTest", Arrays.toString(data));
waiter.countDown();
}
};
set.init(null, callbacks);
// TODO finish it
waitAndAssert(new Waiter<Object[]>() {
@Override
public Object[] waitForData() {
try {
waiter.await(2, TimeUnit.SECONDS);
return LoaderSetAccess.getResults(set);
} catch (final InterruptedException e) {
return null;
}
}
}, new Asserter<Object[]>() {
@SuppressWarnings("unchecked")
@Override
public void makeAssertions(final Object[] data) throws Exception {
assertThat(data.length).isEqualTo(3);
assertThat(((ResponseData<String>) data[0]).getModel()).isEqualTo("R1");
assertThat(((ResponseData<String>) data[1]).getModel()).isEqualTo("R2");
assertThat(((ResponseData<String>) data[2]).getModel()).isEqualTo("R3");
}
});
}
use of android.support.v4.app.LoaderManager in project AndroidTraining by mixi-inc.
the class MainLoaderActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.ListView);
// UIにバインドするデータのカラム名
String[] from = { Book.COLUMN_NAME_BOOK_TITLE, Book.COLUMN_NAME_BOOK_PRICE };
// 指定したカラムのデータを表示するViewのIDを指定します。
int[] to = { R.id.Title, R.id.Price };
// 第3引数のCursorはコールバックで設定されるのでnullを渡しています
mSimpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.list_item_book, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
mListView.setAdapter(mSimpleCursorAdapter);
// ボタンクリックでインサート処理を実行
findViewById(R.id.ADD).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insert();
}
});
// ローダの管理をするオブジェクト
LoaderManager loaderManager = getSupportLoaderManager();
// ローダを初期化して非同期処理を開始する
loaderManager.initLoader(0, null, this);
}
Aggregations