我想用多个ListView填充ViewFlipper。我从数据库中获取了一些部分,然后为每个部分创建一个ListView。 我添加了一个Swipeimplementation来导航列表,这意味着向左滑动将显示下一个列表。 现在的问题是每个列表都包含其行中的图像。每当我想要显示另一个列表时,我必须等到它被加载。
如何构建一个列表并在填充之前将其填入数据中,以便我能够流畅地导航它? 是否有可能保持前一个和下一个在缓存中预先填充?
构建ListViews的方法
public static void prepareViewFlipper()
{
for(int i = 0; i<KundenActivity.namen.size(); i++)
{
ListView list = new ListView(KundenActivity.myref);
menueAdapter = new MenueAdapter(KundenActivity.myref, ArtikelDatabaseHandler.getInstance(KundenActivity.myref).getArtikel(KundenActivity.namen.get(i)));
list.setAdapter(menueAdapter);
switcher.addView(list);
}
}
我的ListAdapter
public class MenueAdapter extends BaseAdapter{
private Activity activity;
private static LayoutInflater inflater= null;
public ArrayList<Artikel> artikel;
Bitmap bm = null;
URL newurl = null;
public MenueAdapter(Activity activity, ArrayList<Artikel> artikel)
{
this.activity = activity;
this.artikel = artikel;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return artikel.size();
}
@Override
public Artikel getItem(int position) {
// TODO Auto-generated method stub
return artikel.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if(convertView == null)
{
vi = inflater.inflate(R.layout.menue_list_item, null);
}
ImageView image = (ImageView) vi.findViewById(R.id.menueimage);
Artikel artikel = getItem(position);
Bitmap bm = Webservice.readBitmapImage(artikel.getItemFoto());
image.setImageBitmap(bm);
return vi;
}
}
SwipeImplementation
SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener()
{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
String swipe="";
float sensitivity = 50;
if(e1.getX() - e2.getX() > sensitivity)
{
swipe = "Swipe Links";
if(canSwipeLeft())
{
MenueFragment.switcher.setInAnimation(getApplicationContext(), R.animator.slide_in_right);
MenueFragment.switcher.setOutAnimation(getApplicationContext(), R.animator.slide_out_left);
Log.d("==SWIPE==", "FORINDEX: "+MenueFragment.index);
MenueFragment.switcher.showNext();
MenueFragment.index++;
Log.d("==SWIPE==", "AFTERINDEX: "+MenueFragment.index);
}
}
else if(e2.getX() - e1.getX() > sensitivity)
{
swipe = "Swipe Rechts";
if(canSwipeRight())
{
MenueFragment.switcher.setInAnimation(getApplicationContext(), R.animator.slide_in_left);
MenueFragment.switcher.setOutAnimation(getApplicationContext(), R.animator.slide_out_right);
Log.d("==SWIPE==", "FORINDEX: "+MenueFragment.index);
MenueFragment.switcher.showPrevious();
MenueFragment.index--;
Log.d("==SWIPE==", "AFTERINDEX: "+MenueFragment.index);
}
}
Toast.makeText(getApplicationContext(), swipe, Toast.LENGTH_SHORT).show();
return super.onFling(e1, e2, velocityX, velocityY);
}
};
GestureDetector gestureDetector = new GestureDetector(simpleOnGestureListener);
我希望任何人都有解决方案。