public class MainActivitytwo extends ActionBarActivity implements OnItemClickListener { private ListView listView1; // private ArrayAdapter<String> arr_adapter; SimpleAdapter adapter; List<Map<String, Object>> list; // ArrayList<Map<String, Object>> data = new ArrayList<Map<String, // Object>>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_activitytwo); listView1 = (ListView) findViewById(R.id.listView1); // 绑定listView1; list=new ArrayList<Map<String, Object>>(); getData(); //这里出现的空指针 adapter = new SimpleAdapter(this,list, // 上下文,当前lisiView加载的每一个列表所对应的的布局文件; R.layout.item, // 调用系统的数据源 new String[] { "book", "author", "image" }, // from new int[] { R.id.bookn, R.id.anthor,R.id.image}); // too listView1.setAdapter(adapter); // 调用一个simpleAdapter listView1.setOnItemClickListener(this); // 监听item } public void addList(View v) { Intent intent = new Intent(); intent.setClass(this, AddMainActivity.class); startActivity(intent); } public void getData() { Bundle bundle = this.getIntent().getExtras(); Map<String, Object> map; if(bundle!=null){ String book = bundle.getString("KEY_BOOK"); String author = bundle.getString("KEY_AUTHOR"); // 创建一个返回值为List的getData方法; // new 一个ArrayList map = new HashMap<String, Object>(); map.put("book", book); map.put("author", author); map.put("image",R.drawable.ic_launcher ); list.add(map); adapter.notifyDataSetChanged();// 这里也出现了空指针 } } @Override public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) { Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.mgn); builder.setItems(R.array.mg, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { switch (arg1) { case 0: break; case 1: list.remove(arg2); adapter.notifyDataSetChanged(); break; } } }); builder.create().show(); }}//注释:其他的文件都完整
添加回答
举报
0/150
提交
取消