android > ListView > 加载res图标

先 是在 res 文件下面 新建 raw 文件夹 然后 放图片放进去

然后是是  布局 login.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView 
		  android:id="@+id/login_list"  
		  android:layout_width="fill_parent"  
		  android:layout_height="wrap_content"  
		  android:drawSelectorOnTop="false"  
		  android:scrollbars="vertical"          
        ></ListView>

   
</LinearLayout>

 

然后是 listview 内部 布局的 xml ,java_list.xml

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" 
    android:padding="8dip"
    >
    <ImageView   
       android:id="@+id/login_list_left"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content"  
       android:layout_alignParentLeft="true"  
       >     
   </ImageView>      
   <TextView   
       android:id="@+id/login_list_right"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content"  
       android:layout_alignParentRight="true"  
       >     
   </TextView>  

</RelativeLayout>

 

 

然后是主 activity , 

 

package login.mft;



import java.util.ArrayList;
import java.util.HashMap;
import remote.mft.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;


public class LoginIndexActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.login);
        ListView list =(ListView)findViewById(R.id.login_list);
        
        //生成冬天数据
        ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String,Object>>();
        for(int i=0;i<10;i++){
        	HashMap<String, Object> map = new HashMap<String, Object>();
        	map.put("ItemImage", R.raw.rdt_right);
        	map.put("ItemTitle", "Level "+i);  
        	listItem.add(map);
        }
        
        SimpleAdapter listItemAdapter = new SimpleAdapter(LoginIndexActivity.this, listItem, 
        		R.layout.login_list, 
        		new String[]{"ItemImage","ItemTitle"}, 
        		new int[]{R.id.login_list_left,R.id.login_list_right}
        );
        
        list.setAdapter(listItemAdapter);
        
        //添加点击
        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				setTitle("点击第"+arg2+"个项目");
			}
		});
        
   
    }
    

	
    

   
}
 

 

** 改变 listview 中 某个 键的值 

 

 

listItem.remove(1); //移除值
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemName", "aa");  
map.put("ItemValue", "bb");  
map.put("ItemIcon", "cc");
listItem.add(1,map);  //添加值
listItemAdapter.notifyDataSetChanged(); //通知更改
 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值