2017-01-07 2 views
1

사용자 지정 어댑터를 사용하여 수행 한 sq-lite에서 데이터를로드하는 목록보기를 만들었습니다. 목록보기가 스크롤되면 목록 항목이 가져옵니다 선택한 있지만 스크롤 할 때 목록 항목을 해제하려면 및 스크롤 끝날 때 사용할 수있는 한 어떻게 할 수 있습니다 싶습니다.목록보기를 스크롤 할 때 목록 항목을 클릭하지 않도록 설정하는 방법

listview.setOnScrollListener(new AbsListView.OnScrollListener() { 

      @Override 
      public void onScrollStateChanged(AbsListView view, int scrollState) { 
       int btn_initPosY = fabaddnew.getScrollY(); 
       int li_initPosY = li_general.getScrollY(); 
       if (scrollState == SCROLL_STATE_TOUCH_SCROLL) { 
        fabaddnew.animate().cancel(); 
        li_general.animate().cancel(); 
        fabaddnew.animate().translationYBy(150); 
        li_general.animate().translationYBy(150); 
       } else { 
        fabaddnew.animate().cancel(); 
        li_general.animate().cancel(); 
        fabaddnew.animate().translationY(btn_initPosY); 
        li_general.animate().translationY(li_initPosY); 
       } 
      } 

      @Override 
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 

       //what is the bottom item that is visible 
       int lastInScreen = firstVisibleItem + visibleItemCount; 

       //is the bottom item visible & not loading more already? Load more! 
       if ((lastInScreen == totalItemCount) && !(loadingMore)) { 

        new LoadDataTask().execute(); 
       } 
      } 
     }); 

어댑터 :

public class Daybook_adapter extends BaseAdapter{ 
Context context; 
Activity activity; 
ArrayList<Daybook> entriesdaybook; 
ArrayList<Daybooklist> daybooklists; 
Daybooklist_adapter adapter; 
DatabaseHandler databaseHandler; 
LinearLayout emptyy; 
double totalamountin = 0.0; 
ExpandableHeightListView daybookdetailviewlist; 



//DaybookSwipeMenuListView daybookdetailviewlist; 
public Daybook_adapter(Activity activity, ArrayList<Daybook> list) { 

    //this.context = context; 
    this.activity = activity; 
    entriesdaybook = list; 

} 


@Override 
public int getCount() { 
    return entriesdaybook.size(); 
} 

@Override 
public Object getItem(int position) { 

    return entriesdaybook.get(position); 
} 

@Override 
public long getItemId(int position) { 

    return position; 
} 



@Override 
public View getView(int position, View convertView, ViewGroup arg2) { 


    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) activity 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.model_daybook, null); 

    } 


    final Daybook m = entriesdaybook.get(position); 
    final TextView tv_date = (TextView) convertView.findViewById(R.id.tv_daybook_date); 
    final TextView tv_cashin = (TextView) convertView.findViewById(R.id.tv_daybook_cashin); 
    final TextView tv_cashout = (TextView) convertView.findViewById(R.id.tv_daybook_cashout); 
    final TextView tv_totalamt = (TextView) convertView.findViewById(R.id.daybook_total_amt); 
    final ImageView img_pdf = (ImageView) convertView.findViewById(R.id.img_printpdf); 
    //final String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); 
    String s = m.getDate(); 
    emptyy = (LinearLayout) convertView.findViewById(R.id.empty); 
    // daybookdetailviewlist = (DaybookSwipeMenuListView) convertView.findViewById(R.id.detaillist_daybook); 
    daybookdetailviewlist = (ExpandableHeightListView) convertView.findViewById(R.id.detaillist_daybook); 

    String[] spiliter = s.split("-"); 
    String year = spiliter[0]; 
    String month = spiliter[1]; 
    String date = spiliter[2]; 
    if (month.startsWith("01")) { 
     tv_date.setText(date + "Jan" + year); 
    } else if (month.startsWith("02")) { 
     tv_date.setText(date + "Feb" + year); 
    } else if (month.startsWith("03")) { 
     tv_date.setText(date + "Mar" + year); 
    } else if (month.startsWith("04")) { 
     tv_date.setText(date + "Apr" + year); 
    } else if (month.startsWith("05")) { 
     tv_date.setText(date + "May" + year); 
    } else if (month.startsWith("06")) { 
     tv_date.setText(date + "Jun" + year); 
    } else if (month.startsWith("07")) { 
     tv_date.setText(date + "Jul" + year); 
    } else if (month.startsWith("08")) { 
     tv_date.setText(date + "Aug" + year); 
    } else if (month.startsWith("09")) { 
     tv_date.setText(date + "Sep" + year); 
    } else if (month.startsWith("10")) { 
     tv_date.setText(date + "Oct" + year); 
    } else if (month.startsWith("11")) { 
     tv_date.setText(date + "Nov" + year); 
    } else if (month.startsWith("12")) { 
     tv_date.setText(date + "Dec" + year); 
    } 


    /* if (m.getUsertype().startsWith("singleworker")) { 
     tv_cashin.setText("\u20B9" + "0"); 
    } else if (m.getUsertype().startsWith("groupworker")) { 
     tv_cashin.setText("\u20B9" + "0"); 
    }*/ 

    tv_cashin.setText("\u20B9" + m.getCashin()); 
    tv_cashout.setText("\u20B9" + m.getCashout()); 
    double one = Double.parseDouble(m.getCashin()); 
    double two = Double.parseDouble(m.getCashout()); 
    double three = one + two; 
    tv_totalamt.setText("\u20B9" + String.valueOf(three)); 
    databaseHandler = new DatabaseHandler(activity); 
    daybooklists = databaseHandler.getAllDaywisedaybookdetails(s); 
    adapter = new Daybooklist_adapter(activity, daybooklists); 
    if (adapter != null) { 
     if (adapter.getCount() > 0) { 
      emptyy.setVisibility(View.GONE); 
      daybookdetailviewlist.setAdapter(adapter); 

     } 
    } else { 
     daybookdetailviewlist.setEmptyView(emptyy); 
    } 
    daybookdetailviewlist.setExpanded(true); 
    daybookdetailviewlist.setFastScrollEnabled(true); 

    img_pdf.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View view, MotionEvent motionEvent) { 

      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
        activity); 

      // set title 
      alertDialogBuilder.setTitle(R.string.app_name); 

      // set dialog message 
      alertDialogBuilder 
        .setMessage("Click yes to Print Report for : "+ m.getDate()) 
        .setCancelable(true) 
        .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          // if this button is clicked, close 
          // current activity 
          Intent pdfreport = new Intent(activity,Activity_Daybookpdf.class); 
          pdfreport.putExtra("date",m.getDate()); 
          activity.startActivity(pdfreport); 
         } 
        }) 
        .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          // if this button is clicked, just close 
          // the dialog box and do nothing 
          dialog.cancel(); 
         } 
        }); 

      // create alert dialog 
      AlertDialog alertDialog = alertDialogBuilder.create(); 

      // show it 
      alertDialog.show(); 
      Button nbutton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE); 
      nbutton.setTextColor(activity.getResources().getColor(R.color.colorAccent)); 
      Button pbutton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); 
      pbutton.setBackgroundColor(activity.getResources().getColor(R.color.colorAccent)); 
      pbutton.setPadding(0, 10, 10, 0); 
      pbutton.setTextColor(Color.WHITE); 
      return false; 
     } 
    }); 


    return convertView; 

} 

public void setTransactionList(ArrayList<Daybook> newList) { 
    entriesdaybook = newList; 
    notifyDataSetChanged(); 
} 

}

+0

내 대답보기, 당신은 어댑터에서 플래그를 설정 clickEnable을 구현할 수 –

+0

내 대답은 작동 했습니까? –

답변

0

이 시도 :

listview.setOnScrollListener(new OnScrollListener() { 

     @Override 
     public void onScrollStateChanged(AbsListView view, int scrollState) { 

      if (scrollState == SCROLL_STATE_IDLE) { 
       Log.i("a", "scrolling stopped..."); 
       isScrolling = false; 
      } 

     } 

     @Override 
     public void onScroll(AbsListView view, int firstVisibleItem, 
       int visibleItemCount, int totalItemCount) { 
      isScrolling = true; 
     } 
    }); 

    listview.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 

      if(!isScrolling){ 
       //do your task 
      } 

     } 
    }); 
+0

하지만 어댑터에 onclick 리스너를주었습니다. 어떻게 할 수 있습니까? –

+0

어댑터 클래스에서 액세스 할 수있는 전역 변수를 isScrolling로 만들 수 있습니다. – rafsanahmad007

1

가 스크롤 검출 수신기를 구현 :

public interface JScrollListener { 
    void onScrollStarted(); 
    void onScrollStopped(); 
} 
,

당신의 ListView 이런 식으로 확장 :

public class JListView extends ListView { 
    private static final long OFFSET_DELAY = 150; 
    private boolean isScrolling; 
    private JScrollListener jScrollListener; 

    public JListView(Context context) { 
     super(context); 
    } 

    public JListView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public JListView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    public JListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    public void setJScrollListener(JScrollListener jScrollListener) { 
     this.jScrollListener = jScrollListener; 
    } 

    Handler handler; 
    @Override 
    protected void onScrollChanged(int l, int t, int oldl, int oldt) { 
     super.onScrollChanged(l, t, oldl, oldt); 
     if(!isScrolling) { 
      isScrolling = true; 
      if(jScrollListener!=null) 
       jScrollListener.onScrollStarted(); 
     } 
     if(handler!=null) 
      handler.removeCallbacksAndMessages(null); 
     else 
      handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       if(isScrolling) { 
        isScrolling = false; 
        if(jScrollListener!=null) 
         jScrollListener.onScrollStopped(); 
       } 
      } 
     }, OFFSET_DELAY); 
    } 
} 

이 좋아 사용 :

JListView jListView = (JListView) findViewById(R.id.jListView); 
jListView.setJScrollListener(new JScrollListener() { 
      @Override 
      public void onScrollStarted() { 
       clickEnabled(false); 
      } 

      @Override 
      public void onScrollStopped() { 
       clickEnabled(true); 
      } 
     }); 

희망이 당신을 도울 것입니다!

관련 문제