• ListView


    设计一个ListView,放置中国各省的省会城市,并为每一个省会城市安放对应图片。

    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.widget.ListView;
    import android.widget.SimpleAdapter;
    
    public class MainActivity extends Activity {
    	ListView listView;
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		listView=(ListView)findViewById(R.id.lv);
    		SimpleAdapter adapter=new SimpleAdapter(this, getData(), R.layout.second_activity, new String[]{"tet","img"},new int[]{R.id.tet,R.id.img});
    		listView.setAdapter(adapter);	
    	}
    	private List<Map<String,Object>> getData(){
    		List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
    		Map<String, Object> map=new HashMap<String, Object>();
    		map.put("tet", "上海");
    		map.put("img", R.drawable.shanghai);
    		list.add(map);
    		
    		map=new HashMap<String, Object>();
    		map.put("tet", "澳门");
    		map.put("img", R.drawable.aomen);
    		list.add(map);
    		
    		map=new HashMap<String, Object>();
    		map.put("tet", "福州");
    		map.put("img", R.drawable.fuzhou);
    		list.add(map);
    		
    		map=new HashMap<String, Object>();
    		map.put("tet", "深圳");
    		map.put("img", R.drawable.shenzhen);
    		list.add(map);
    		
    		map=new HashMap<String, Object>();
    		map.put("tet", "温州");
    		map.put("img", R.drawable.wenzhou);
    		list.add(map);
    		
    		map=new HashMap<String, Object>();
    		map.put("tet", "厦门");
    		map.put("img", R.drawable.xiamen);
    		list.add(map);
    		return list;
    	}
    }
    

    布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <ImageView
            android:id="@+id/img"
            android:layout_width="30px"
            android:layout_height="30px"
            android:layout_marginLeft="5px" />
    
        <TextView
            android:id="@+id/tet"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15px" />
    
    </LinearLayout>


  • 相关阅读:
    【某集训记录】
    【bzoj 4407】于神之怒加强版
    【bzoj 3529】【sdoi 2014】数表
    PHP消息队列实现及应用
    (转)PHP DB 数据库连接类
    站点http升级到https
    虚拟主机发送邮件出现getmypid禁用的解决方案
    企业微信API集成登录以及其他操作开发
    微信小程序发送模版消息常见错误解决方案
    (转) Laravel自带SMTP邮件组件实现发送邮件(QQ、163、企业邮箱都可)
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6834900.html
Copyright © 2020-2023  润新知