.Net程序员玩转Android开发--ListView单击事件_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > .Net程序员玩转Android开发--ListView单击事件

.Net程序员玩转Android开发--ListView单击事件

 2014/12/30 17:00:28  GC2013  程序员俱乐部  我要评论(0)
  • 摘要:publicclassListViewClickActivityextendsActivity{privateListViewlv;SimpleAdapteradp;//定义适配器privateList<map<string,object>>mapList;//定义数据源protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate
  • 标签:事件 程序 .net android 程序员 view list net 开发 Android开发

public class ListViewClickActivity extends Activity {
    
    private ListView lv; 
      SimpleAdapter adp;//定义适配器 
       private List<map<string,object>> mapList;//定义数据源 
       
       
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listviewclicklay);
        lv=(ListView)findViewById(R.id.listView1);
        
        mapList=new ArrayList<map<string,object>>(); 
            for(int i=0;i<10;i++)
            {
            
                Map<string,object> map=new HashMap<string,object>(); 
                map.put(code,编码:1000+i); 
                map.put(name,名称:Ipad+i);
                map.put(price,价格:+i);
                map.put(model,单位:+i);
                 mapList.add(map); 
            }
            
             adp=new SimpleAdapter(ListViewClickActivity.this, mapList,R.layout.listdetail, new String[]{code,name,price,model}, new int[]{R.id.tvcode,R.id.tvname,R.id.tvprice,R.id.tvmodel});
              lv.setAdapter(adp); 
              
              lv.setOnItemClickListener(new OnItemClickListener() {  
                    @Override
                    public void onItemClick(AdapterView<!--?--> arg0,View arg1, int arg2,  
                            long arg3) {  
                       
           
                        TextView   tname= (TextView)arg1.findViewById(R.id.tvname);//名称 
                        TextView   tmodel= (TextView)arg1.findViewById(R.id.tvmodel);//规格
                        TextView   tprice= (TextView)arg1.findViewById(R.id.tvprice);//单价
                        TextView   tcode= (TextView)arg1.findViewById(R.id.tvcode);//编码
            
                        Toast.makeText(getApplicationContext(),当前商品 名称:+tname.getText()+,编码:+tcode.getText(),30).show(); 
 
                    }  
                }); 
        
    }
    
    
 
}</string,object></string,object></map<string,object></map<string,object>

发表评论
用户名: 匿名