1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.widget.listview;
18 
19 import android.app.ListActivity;
20 import android.os.Bundle;
21 import android.os.Handler;
22 import android.view.View;
23 import android.widget.AbsListView;
24 import android.widget.AdapterView;
25 import android.widget.ArrayAdapter;
26 import android.widget.TextView;
27 
28 import com.android.frameworks.coretests.R;
29 
30 /**
31  * Exercises change notification in a list
32  */
33 public class ListScrollListener extends ListActivity implements AbsListView.OnScrollListener {
34     Handler mHandler = new Handler();
35     TextView mText;
36 
37     @Override
onCreate(Bundle icicle)38     public void onCreate(Bundle icicle) {
39         super.onCreate(icicle);
40 
41         setContentView(R.layout.list_scroll_listener);
42 
43         String values[] = new String[1000];
44         int i=0;
45         for(i=0; i<1000; i++) {
46             values[i] = ((Integer)i).toString();
47         }
48 
49         mText = findViewById(R.id.text);
50         setListAdapter(new ArrayAdapter<String>(this,
51                 android.R.layout.simple_list_item_1, values));
52 
53 
54         getListView().setOnScrollListener(this);
55     }
56 
onItemSelected(AdapterView parent, View v, int position, long id)57     public void onItemSelected(AdapterView parent, View v, int position, long id) {
58         mText.setText("Position " + position);
59     }
60 
onNothingSelected(AdapterView parent)61     public void onNothingSelected(AdapterView parent) {
62         mText.setText("Nothing");
63     }
64 
onScroll(AbsListView view, int firstCell, int cellCount, int itemCount)65     public void onScroll(AbsListView view, int firstCell, int cellCount, int itemCount) {
66         int last = firstCell + cellCount - 1;
67         mText.setText("Showing " + firstCell + "-" + last + "/" + itemCount);
68     }
69 
onScrollStateChanged(AbsListView view, int scrollState)70     public void onScrollStateChanged(AbsListView view, int scrollState) {
71     }
72 }
73