⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pickup.java

📁 Google Android应用框架原理与程序设计 第三版(中文高清PDF)高焕堂
💻 JAVA
字号:
package com.misoo.ex01_03;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class pickup extends Activity {
	    /** Called when the activity is first created. */
		private ListView lv;
		private Map<String, Object> item; 
	    private List<Map<String, Object>> coll;
	    @Override
	    public void onCreate(Bundle icicle) {
	        super.onCreate(icicle);
	        coll = new ArrayList<Map<String, Object>>();
	        lv = new ListView(this);
	        this.addData();
	        SimpleAdapter adapter = new SimpleAdapter(this, coll,
	                android.R.layout.simple_list_item_1, new String[] { "title" },
	              new int[] {android.R.id.text1});
	        lv.setAdapter(adapter);
	        lv.setOnItemClickListener(listener);
	        setContentView(lv);
	    }
	    
	    OnItemClickListener listener = new OnItemClickListener()
	    {
	    	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
	    		String str = coll.get(arg2).get("price").toString();
	    		Bundle bundle = new Bundle();
	 		    bundle.putString("DataKey", str);
	 		    Intent mIntent = new Intent();
	 		    mIntent.putExtras(bundle);
	 		    setResult(RESULT_OK, mIntent);
		   	    finish();
			} 
	      };
	     protected void addData() {
	    	// "<item><prod_na>Linux</prod_na><prod_type>ST</prod_type></item>"
	     	 item = new HashMap<String, Object>();
	         item.put("title", "Item-1");
	         item.put("price", "US$50");
	         coll.add(item);
	         // "<item><prod_na>Windows</prod_na><prod_type>Mobile</prod_type></item>"
	         item = new HashMap<String, Object>();
	         item.put("title", "Item-2");
	         item.put("price", "US$800");
	         coll.add(item);
	         item = new HashMap<String, Object>();
	         item.put("title", "Item-3");
	         item.put("price", "US$777");
	         coll.add(item);
	    } 
	 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -