2011-11-11 16 views
1

私は10アイテムをロードしているリストビューを持っています。リストビューで3つのアイテムのみを表示する方法

スクロールすると3つのアイテムしか表示されません。

リストの高さを調整してやりたくないので、スクロールしなくても3つのアイテムしか表示しない(部分的に表示されないアイテムを意味する)。

これを達成する方法...?

ありがとうございます。

+1

これを確認してください:http://stackoverflow.com/questions/6573489/android-endless-scrolling-listview-and-cursor/6759834#6759834これがあなたの問題を解決することを願っています。 – Ian

+0

@ Amy88このコメントを答えとして...! – Noby

+0

これを回答として追加しようとすると、自動的に「コメントに変換された簡単な回答」** **を示すコメントに変換されます。アンウェイはNobyに感謝します。私があなたを助けることができることを知ってよかった。 – Ian

答えて

2

スクロールイベントごとに10レコードずつ入力したコードを投稿します。

/** 
    * Called when the activity is first created. 
    * 
    * @param savedInstanceState 
    *   the saved instance state 
    */ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.view_checkin_checkout_history); 

      Thread thread = new Thread() { 

      public void run() { 

         synchronized (this) { 
        fetchHistory(0); 

        handler.post(new Runnable() { 
         public void run() { 
          pd.dismiss(); 

          displayUI(); 
         }; 
        }); 
       } 
      } 
     }; 

     thread.start(); 
     } 

     /** 
    * Display the check in check out history list. 
    */ 
    private void displayUI() { 
     if ((checkInCheckOutHistoryList != null) 
       && (checkInCheckOutHistoryList.size() > 0)) { 
      historyArrayList = new ArrayList<HashMap<String, String>>(); 

      histroyListAdapter = new SimpleAdapter(
        ViewCheckInCheckOutHistory.this, historyArrayList, 
        R.layout.multi_colummn_list_text_style_small, new String[] { 
          "assetTag", "gif" , "action", "actionTime"}, 
        new int[] { R.id.list_content_column1, 
          R.id.list_content_imagecolumn, 
          R.id.list_content_column3, 
          R.id.list_content_column4}); 

      // To add more items to list view on scroll event. 
      historyListView.setOnScrollListener(new OnScrollListener() { 

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

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

        int lastInScreen = firstVisibleItem + visibleItemCount; 

        if ((lastInScreen == totalItemCount) && !(loadingMore) && (lastInScreen < totalHistoryItemCount)) { 

         if (!firstInstance) { 
          openSlider();       
         }       

         fetchHistory(lastInScreen);  

         Thread thread = new Thread(null, loadMoreListItems); 
         thread.start(); 
        } 
       } 
      }); 
        } 
        } 

// Runnable to load the items 

    private Runnable loadMoreListItems = new Runnable() { 

     @Override 
     synchronized public void run() { 
      // Set flag so we cant load new items 2 at the same time 
      loadingMore = true; 

      HashMap<String, String> historyObjectMap; 

      for (CheckInCheckOutHistory checkOutHistoryObj : checkInCheckOutHistoryList) { 
       historyObjectMap = new HashMap<String, String>(); 
       historyObjectMap.put("assetTag", 
         checkOutHistoryObj.getAssetTag()); 
       historyObjectMap.put("action", checkOutHistoryObj.getAction()); 
       historyObjectMap.put("actionTime", 
         checkOutHistoryObj.getActionDate()); 

       if (checkOutHistoryObj.getAction().equals("Checked out")) { 
        historyObjectMap.put("gif", R.drawable.radio_button_yellow 
          + ""); 
       } else { 
        historyObjectMap.put("gif", R.drawable.radio_button_green 
          + ""); 
       } 

       historyArrayList.add(historyObjectMap); 
      } 

      runOnUiThread(returnRes); 
     } 
    }; 

    // Since we cant update our UI from a thread this Runnable takes care of 
    // that! 
    private Runnable returnRes = new Runnable() { 
     @Override 
     public void run() { 

      // Add the new items to the adapter 
      if (historyArrayList != null && historyArrayList.size() > 0) { 
       histroyListAdapter.notifyDataSetChanged(); 
      } 

      if (firstInstance) { 
       historyListView.setAdapter(histroyListAdapter); 
       firstInstance = false; 
      } 

      historyListLayout.setVisibility(View.VISIBLE); 

      // Done loading more. 
      loadingMore = false; 

      if ((slidingDrawer.isOpened()) && (!loadingMore)) { 

       handler.postDelayed(new Runnable() { 

        @Override 
        public void run() { 
         slidingDrawer.close(); 
         slidingDrawer.setVisibility(View.GONE); 
        } 
       }, 1000); 

      } 
     } 
    }; 


fetchHistory(int count) IはtotalHistoryItemCount & checkInCheckOutHistoryListの値を設定するために使用した方法です。

これが役に立ちます。

0

これらの3つのアイテムを除いて、スクロールすると他のアイテムはすべて非表示になります。

+0

http://developer.android.com/reference/android/view/View.html#GONEをご覧ください。 – Pedantic

関連する問題