package com.example.ff.myapplication; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class TextView extends Activity implements AdapterView.OnItemClickListener,ViewTreeObserver.OnScrollChangedListener, AbsListView.OnScrollListener { private ListView listView; private SimpleAdapter Sim_adapter; private List<Map<String,Object>> datalist; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.textview); listView= (ListView) findViewById(R.id.listView); datalist=new ArrayList<Map<String, Object>>(); Sim_adapter=new SimpleAdapter(this,getData(),R.layout.item,new String[]{"pic","text"},new int[]{R.id.pic,R.id.text_list}); listView.setAdapter(Sim_adapter); listView.setOnItemClickListener(this); listView.setOnScrollListener(this); } private List<Map<String,Object>> getData(){ for (int i=0;i<20;i++){ Map<String, Object>map=new HashMap<String,Object>(); map.put("pic",R.mipmap.ic_launcher); map.put("text","慕课网"+i); datalist.add(map); } return datalist; } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text=listView.getItemAtPosition(position)+""; Toast.makeText(this,"postion="+position+" text="+text,Toast.LENGTH_LONG).show(); } @Override public void onScrollChanged() { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { switch (scrollState){ case SCROLL_STATE_FLING: Log.i("main", "用户在手指离开屏幕之前,用力划一下,视图仍依靠惯性继续滑动"); break; case SCROLL_STATE_IDLE: Log.i("main","视图已经停止滑动"); break; case SCROLL_STATE_TOUCH_SCROLL: Log.i("main", "手指没有离开屏幕,视图正在滑动"); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }
一条小咸鱼
一条小咸鱼
相关分类