0

我想用多个 ListViews 填充 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);
    }
}

我的列表适配器

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;
}

}

Swipe实现

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);

我希望有人有解决方案。

4

0 回答 0