public class MainActivity extends Activity { private PersonService service; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); service = new PersonService(this); ListView listView = (ListView) this.findViewById(R.id.listView); //获取游标 Cursor cursor = service.getCursorScrollData(0, 10); //创建SimpleCursorAdapter适配器将数据绑定到item显示控件上 SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, new String[]{"name", "phone", "amount"}, new int[]{R.id.name, R.id.phone, R.id.amount}); listView.setAdapter(adapter); //条目点击事件 listView.setOnItemClickListener(new ItemClickListener()); } private final class ItemClickListener implements OnItemClickListener{ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ListView listView = (ListView) parent; Cursor cursor = (Cursor) listView.getItemAtPosition(position); String personid = String.valueOf(cursor.getInt(cursor.getColumnIndex("_id"))); Toast.makeText(getApplicationContext(), personid, 1).show(); } } }
Android采用ListView实现数据列表显示
内容版权声明:除非注明,否则皆为本站原创文章。