main.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" >    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ListView  
        android:id="@+id/list1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false"
        android:scrollbars="vertical"/>
</LinearLayout>user.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="horizontal" >    <ImageView android:id="@+id/photo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
        <TextView
            android:id="@+id/user"
            android:layout_width="180dip"
            android:layout_height="30dip"
            android:textSize="10pt"/>
        
       
        
            
           </LinearLayout>程序代码package my.listview1;import java.util.ArrayList;
import java.util.HashMap;import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.app.ListActivity;
import android.graphics.Bitmap;
import android.widget.ImageView;
public class Listview1 extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListView list1 = (ListView) findViewById(R.id.list1);
        ArrayList<HashMap<Object,String>> list = new  ArrayList<HashMap<Object,String>>();
        HashMap<Object,String> map1 = new HashMap<Object,String>();
        HashMap<Object,String> map2 = new HashMap<Object,String>();
        map1.put("photo", R.drawable.hmode);
        map1.put("user", "maliming");
        map2.put("photo", R.drawable.vulfix);
        map2.put("user", "zhangsan");
        list.add(map1);
        list.add(map2);
        SimpleAdapter listAdapter = new SimpleAdapter(this, list, R.layout.use,
         new String[]{ "photo","user"},
         new int[]{R.id.photo,R.id.user});
        listAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
         public boolean setViewValue(View view,Object data,String textRepresentation){
         if(view instanceof ImageView && data instanceof Bitmap){
         ImageView iv = (ImageView) view;
         iv.setImageBitmap((Bitmap)data);
         return true;
        
         }else{
         return false;
         }
         }
        });
        list1.setAdapter(listAdapter);
        
    }
    
}

解决方案 »

  1.   

    错误提示the method put(Object,string)in the type HashMap<object,string>is not applicable for the arguments(string ,int),
      

  2.   

    如果你要继承ListActivity,那么你的listView的id必须是@android:id/list
      

  3.   

    [color=#FF0000]HashMap<Object,String> map1 = new HashMap<Object,String>();        HashMap<Object,String> map2 = new HashMap<Object,String>();[/color]        map1.put("photo", R.drawable.hmode);
            map1.put("user", "maliming");
            map2.put("photo", R.drawable.vulfix);
            map2.put("user", "zhangsan");
    你的两个Map限定了key类型为Object,Value类型为String ,下面put的时候value类型给int型,这个当然put不进去的
      

  4.   

    put的类型不对,当然报错了。应该定义成HashMap<String,Object> map1 = new HashMap<String,Object>(); 
      

  5.   

    先谢了,改过之后就行了,不过为什么?
    为什么要把
    ArrayList<HashMap<Object,String>> list = new  ArrayList<HashMap<Object,String>>();
            HashMap<Object,String> map1 = new HashMap<Object,String>();
            HashMap<Object,String> map2 = new HashMap<Object,String>();
    中的Object核String换过来
      

  6.   


    ......HashMap的定义形式是HashMap<key,value>;根据你下面代码中要put的key和value值。当然应该定义成HashMap<String,Object>