WebからJSONデータから3つのランダムな画像を表示するアクティビティがあります。各ランダム画像はクリック可能であり、タイトル、画像、説明などを含む詳細アクティビティにつながります。表示されている画像は互いに異なります。
Cursor
インターネット接続がないときはいつでも、アプリケーションが外部ストレージのキャッシュから画像データを読み取るように、SQLiteとそのアクティビティを実装する必要があります。私はすでにデータベース、プロバイダー、同期のクラスを持っています。次の列を持つSQLiteデータベースがあります。
BaseColumns._ID
Database.Project.C_SMALLIMAGE
これが私がこれまでに持っているコードのスニペットです:
void doSync() {
Intent serviceIntent = new Intent(this, LooserSync.class);
startService(serviceIntent);
}
このメソッドは、URLを配置したWebサービスを呼び出します。これはロードされた画像です:
public void setViewImage(ImageView v, String value) {
v.setTag(value);
loader.DisplayImage(value, context, v);
}
これは、画像をランダム化してクリック可能にする私の古い関数です。
prjcts = new ArrayList<Project>();
int max = prjcts.size();
System.out.println(max);
List<Integer> indices = new ArrayList<Integer>(max);
for(int c = 1; c < max; ++c) {
indices.add(c);
}
Random r = new Random();
int arrIndex = r.nextInt(indices.size());
int randomIndex1 = indices.get(arrIndex);
indices.remove(arrIndex);
これは私がこれまでの私の活動で持っているものです:
int arrIndex2 = r.nextInt(indices.size());
int randomIndex2 = indices.get(arrIndex2);
indices.remove(arrIndex2);
int arrIndex3 = r.nextInt(indices.size());
int randomIndex3 = indices.get(arrIndex3);
indices.remove(arrIndex3);
imageLazy(image1, prjcts.get(randomIndex1),Main.this);
imageLazy(image2, prjcts.get(randomIndex2),Main.this);
imageLazy(image3, prjcts.get(randomIndex3),Main.this);
image1.setOnClickListener(new RandomClickListener(randomIndex1));
image2.setOnClickListener(new RandomClickListener(randomIndex2));
image3.setOnClickListener(new RandomClickListener(randomIndex3));
public void imageLazy(final ImageView image,Project pro,Activity activity) {
String imageurl = pro.smallImageUrl;
image.setTag(imageurl);
loader.DisplayImage(imageurl, activity,image);
}
public class RandomClickListener implements View.OnClickListener {
private final int randomIndex;
public RandomClickListener(final int randomIndex) {
this.randomIndex = randomIndex;
}
@Override
public void onClick(View v) {
Intent top = new Intent(Main.this, DetailsActivity.class);
top.putExtra("spendino.de.ProjectDetail.position", randomIndex);
/*
top.setData(Uri.withAppendedPath(Uri.withAppendedPath(
LooserProvider.CONTENT_URI, Database.Project.NAME), Long.toString(id)));
*/
startActivity(top);
}
}
画像の詳細を取得する関数は次のとおりです。
Uri uri = Uri.withAppendedPath(Uri.withAppendedPath( LooserProvider.CONTENT_URI, Database.Project.NAME), Long .toString(id));
Cursor managedCursor = managedQuery( uri, new String[] { BaseColumns._ID, Database.Project.C_BIGIMAGE }, null, null, "RANDOM() LIMIT 3");
これらのスニペットからコードを構築する方法について何か提案はありますか?