Back to project page sms_modi.
The source code is released under:
GNU General Public License
If you think the Android project sms_modi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.zhufeng.sms_mod; // w ww . j a v a 2 s .co m import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.CheckBox; import android.widget.ListView; import android.widget.SimpleAdapter; public class ListViewDemo extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list_view_demo); // ????ListView?? ListView mListView = (ListView) findViewById(R.id.listview); // ?????????????,mFrom?mTo???????? String[] mFrom = new String[] { "img", "title1", "title2", "time" }; int[] mTo = new int[] { R.id.img, R.id.title1, R.id.title2, R.id.time }; // ????????,???????10???????,??????????????????????????? List<Map<String, Object>> mList = new ArrayList<Map<String, Object>>(); Map<String, Object> mMap = null; for (int i = 0; i < 10; i++) { mMap = new HashMap<String, Object>(); mMap.put("img", R.drawable.ic_launcher); mMap.put("title1", "??"); mMap.put("title2", "???"); mMap.put("time", "2011-08-15 09:00"); mMap.put("checked", true); mList.add(mMap); } // ?????? SimpleAdapter mAdapter = new SimpleAdapter(this, mList, R.layout.activity_list_view_demo, mFrom, mTo) { @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); @SuppressWarnings("unchecked") final HashMap<String, Object> map = (HashMap<String, Object>) this .getItem(position); // ??????View??Checkbox?? CheckBox checkBox = (CheckBox) view.findViewById(R.id.checked); checkBox.setChecked((Boolean) map.get("checked")); // ????????,?map?????? checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { map.put("checked", ((CheckBox) view).isChecked()); } }); return view; } }; mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { @SuppressWarnings("unchecked") // ????????item???????? HashMap<String, Object> map = (HashMap<String, Object>) parent .getItemAtPosition(position); // ????????????? } }); System.out.println("test on Activity_List_View_Demo"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.list_view_demo, menu); return true; } }