-1

I am working on an Android project which contain a listview that shows three items at first then it will reload new three items when scrolled to the left. Please tell me some concept to do that.

Junior Frogie
  • 313
  • 1
  • 3
  • 16

2 Answers2

2

If you need a listview that scrolls horizontally, then you should use a RecyclerView with a LinearLayoutManager configured for horizontal scroll instead. ListView only scrolls vertically.

Francesc
  • 25,014
  • 10
  • 66
  • 84
  • 1
    RecyclerView doesn't support low version. And I have to use listview :( – Junior Frogie Mar 07 '16 at 01:28
  • 1
    RecyclerView is in the support library, goes all the way down to V7 (Eclair). How low do you need to go? There is no point in supporting anything below 16, but if you push it, 11 is as low as you should get. – Francesc Mar 07 '16 at 01:31
1
    class GestureList extends ListView {
   int flag=BaseActivity.flag;
   Context context;
   GestureDetector gestureDetector;

   public GestureList(Context context, AttributeSet attrs) {
     super(context, attrs);
     this.context=context;
     gestureDetector=new GestureDetector(context,new Gesture(context));     
   }
   public GestureList(Context context, AttributeSet attrs, int defStyle) {
     super(context, attrs, defStyle);
     // TODO Auto-generated constructor stub
     this.context=context;
     gestureDetector=new GestureDetector(context,new Gesture(context));
   }
   public GestureList(Context context) {
     super(context);
     // TODO Auto-generated constructor stub
     this.context=context;
     gestureDetector=new GestureDetector(context,new Gesture(context));
   }
   @Override
   public boolean onTouchEvent(MotionEvent ev) {

     if(gestureDetector.onTouchEvent(ev)) return true;
     return super.onTouchEvent(ev);
   }  
}

___________________________________

    public class Gesture implements OnGestureListener{

  int flag=BaseActivity.flag;

  int length=BaseActivity.myClass.length;
  Class[] myClass=BaseActivity.myClass;
  Context context;
  public Gesture(Context context) {
     // TODO Auto-generated constructor stub
     this.context=context;
  }
  @Override
  public boolean onDown(MotionEvent e) {
     // TODO Auto-generated method stub
     return false;
  }

  @Override
  public void onShowPress(MotionEvent e) {
     // TODO Auto-generated method stub

  }
  @Override
  public boolean onSingleTapUp(MotionEvent e) {
     // TODO Auto-generated method stub
     return false;
  }
  @Override
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
       float distanceY) {
     // TODO Auto-generated method stub
     return false;
  }
  @Override
  public void onLongPress(MotionEvent e) {
     // TODO Auto-generated method stub

  }
  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
       float velocityY) {           
      //left
        if (e1.getX() - e2.getX() > 50) { 
          Log.i("Fling", "Gesture:left "); 
          if (++flag>=length) {
         flag=length-1;
       BaseActivity.flag=flag;
         return true;
       }       
          BaseActivity.flag=flag;
     Intent intent=new Intent(context, myClass[flag]);

     intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent. FLAG_ACTIVITY_REORDER_TO_FRONT);

     context.startActivity(intent);     
     return true; 
        }
        else if (e2.getX() - e1.getX()>50) {
          Log.i("Fling", "Gesture:right "); 
      if (--flag<0) {
         flag=0;

       BaseActivity.flag=flag;
         return true;
       }       
      BaseActivity.flag=flag;
     Intent intent=new Intent(context,myClass[flag]);

     intent.setFlags(Intent. FLAG_ACTIVITY_NO_HISTORY|Intent. FLAG_ACTIVITY_REORDER_TO_FRONT);  
     context.startActivity(intent); 
//       System.exit(0);         
     return true; 
        } 
        return true; 
  }
}

_______________________________________


    <com.jph.custom.GestureList android:id="@+id/list"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:focusable="false"
        />
TanLingxiao
  • 402
  • 5
  • 7