ListView scroll interface and click event, listview scroll event
MainActivity
Package com. lib. listviewtest; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. support. v7.app. appCompatActivity; import android. view. view; import android. widget. adapterView; import android. widget. arrayAdapter; import android. widget. listView; import android. widget. toast; public class MainActivity extends AppCompatActivity {private String [] data = {"Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape ", "Pineapple", "Strawberry", "Cherry", "Mango", "weijize1", "weijize2", "weijize3", "weijize4 "}; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); final ArrayAdapter
Adapter = new ArrayAdapter
(MainActivity. this, android. r. layout. simple_list_item_1, data); ListView listView = (ListView) findViewById (R. id. list_view); listView. setAdapter (adapter); listView. setOnItemClickListener (new android. widget. adapterView. onItemClickListener () {@ Override public void onItemClick (AdapterView
Parent, View view, int position, long id) {setTitle ("click" + (position + 1) + "items"); // Toast. makeText (MainActivity. this, data [position], Toast. LENGTH_SHORT ). show (); showToast (MainActivity. this, data [position], 500) ;}}) ;}/ *** display toast, define the display length by yourself. * Param1: The activity passes in the context * param2: the content of the toast we need to display * param3: time length long type, the length of time we pass in (such as 500) */public static void showToast (final Activity activity, final String word, final long time) {activity. runOnUiThread (new Runnable () {public void run () {final Toast toast = Toast. makeText (activity, word, Toast. LENGTH_LONG); toast. show (); Handler handler = new android. OS. handler (); handler. postDelayed (new Runnable () {public void run () {toast. cancel () ;}}, time );}});}}
Activity_main.xml