일일히 등록해야 하는 코드더군요. 근데 보통 갤러리는 폴더에 있는걸 자동으로 읽지 않습니까?
아래 코드에서 폴더에 있는 그림들 자동으로 읽으려면 어떻게 수정해야 하는지 알려주세요.
package org.snowpard.proects.eighteen;
import java.util.ArrayList;
import java.util.List;
import java.net.Socket;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.AnimationUtils;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewFlipper;
public class MainActivity extends Activity {
private ViewFlipper gallery;
private TextView txtPages;
private CheckBox checkBoxLoop;
private float fromPosition;
private int count;
private List<Bitmap> items;
private LayoutInflater inflater = null;
String ip = "127.0.0.1";
int port_number = 8888;
private void initList()
{
items = new ArrayList<Bitmap>();
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_0));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_1));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_2));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_3));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_4));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_5));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_6));
items.add(BitmapFactory.decodeResource(getResources(), R.drawable.sample_7));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initList();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.txtPages = (TextView)findViewById(R.id.txtPages);
this.checkBoxLoop = (CheckBox)findViewById(R.id.checkBoxLoop);
this.gallery = (ViewFlipper)findViewById(R.id.gallery);
this.gallery.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
fromPosition = event.getX();
break;
case MotionEvent.ACTION_UP:
float toPosition = event.getX();
if (fromPosition > toPosition + 20)
{
next();
return true;
}
else if (fromPosition < toPosition - 20)
{
previous();
return true;
}
default:
break;
}
return true;
}
});
gallery.addView(addImage(items.get(0)));
updateTextView();
}
public void next()
{
if (count >= items.size() - 1 && !checkBoxLoop.isChecked())
return;
else if (count >= items.size() - 1 && checkBoxLoop.isChecked())
count = -1;
count++;
addNextImage(count, false);
gallery.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.go_next_in));
gallery.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.go_next_out));
gallery.showNext();
removeImages();
updateTextView();
}
------하략