zoukankan      html  css  js  c++  java
  • 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>


  • 相关阅读:
    新机自动创建yum库
    一段自动添加证书命令
    一段托盘程序
    date
    1234567890 转换成 1,234,567,890
    删除localStorage数组中其中一个元素(根据元素中的属性key)
    xcode6 ios launchimage
    画分割线
    裁剪和打水印
    UITextView添加一个placeholder功能
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6834900.html
Copyright © 2011-2022 走看看