本帖最后由 lok_le 于 2011-04-30 17:30:20 编辑

解决方案 »

  1.   

    这是java文件
    private ListView mListView;
    private SimpleAdapter mAdapter;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            
         super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            
            //
            ArrayList<Map<String,Object>> mList= new ArrayList<Map<String, Object>>();
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("title", "G1");
            map.put("info", "google 1");
            map.put("img", R.drawable.icon);
            mList.add(map);
            map = new HashMap<String, Object>();
            map.put("title", "G2");
            map.put("info", "google 2");
            map.put("img", R.drawable.icon);
            mList.add(map);
            map = new HashMap<String, Object>();
            map.put("title", "G3");
            map.put("info", "google 3");
            map.put("img", R.drawable.icon);
            mList.add(map);;
            //
            mAdapter=new SimpleAdapter(this,mList,R.layout.sss,new String[]{"title","info","img"},new int[]{R.id.textview1,R.id.textview2,R.id.imageview1});
            mListView.setAdapter(mAdapter);
      

  2.   

    这是布局文件,一个主窗口,一个ListViewItem的布局
    主窗口
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    <ListView 
    android:id="@+id/listview1" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent"/>
    </LinearLayout>
    ListViewItem布局
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView 
    android:id="@+id/imageview1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5px"/>
    <LinearLayout android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/textview1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFFFF"
    android:textSize="22px" 
    android:text="textview1"/>
    <TextView android:id="@+id/textview2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFFFF"
    android:textSize="13px" 
    android:text="textview2"/>
     </LinearLayout>
     </LinearLayout>
      

  3.   

    今天又做了个LISTVIEW用到SIMPLECURSORVIEW的,发现还是有这种情况。
    请问有人知道问什么吗??!!
      

  4.   

    private ListView mListView;
    private SimpleAdapter mAdapter;
      @Override
      public void onCreate(Bundle savedInstanceState) {
        
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);//mListView必须在R.layout.main布局中
      
      mListView = (ListView)findViewById(R.id.listview1);  
        
      //
      ArrayList<Map<String,Object>> mList= new ArrayList<Map<String, Object>>();
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("title", "G1");
      map.put("info", "google 1");
      map.put("img", R.drawable.icon);
      mList.add(map);
      map = new HashMap<String, Object>();
      map.put("title", "G2");
      map.put("info", "google 2");
      map.put("img", R.drawable.icon);
      mList.add(map);
      map = new HashMap<String, Object>();
      map.put("title", "G3");
      map.put("info", "google 3");
      map.put("img", R.drawable.icon);
      mList.add(map);;
      //
      mAdapter=new SimpleAdapter(this,mList,R.layout.sss(该参数为ListViewItem的布局),new String[]{"title","info","img"},new int[]{R.id.textview1,R.id.textview2,R.id.imageview1});
      mListView.setAdapter(mAdapter);
      

  5.   

    是这样,不知到楼主声明的mListView定义了吗?没看到java中对其定义的地方,也就是楼上说的赋值的地方。
      

  6.   

    谢谢两位的帮助,的确很粗心。
    可是我还有一个SimpleCursorAdapter的小程序,这次Widget都有定义,可是同样发生了RUNTimeException的异常,能否帮忙查看。我已经通过检测发现错误出在
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list, mCursor, new String[]{ myHelper.col2_name }, new int[]{ R.id.listTextView1 });这句。因为前面的输出都有输出。下面是简要代码。
      

  7.   

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            //
            mEditText=(EditText)findViewById(R.id.edittext1);
            mListView=(ListView)findViewById(R.id.listview1);
            //
            mHelper=new myHelper(this);
            mCursor=mHelper.select();
            //startManagingCursor(mCursor);
            for(int i=0;i<mCursor.getColumnCount();i++)
            {
             System.out.println("Column "+i+":"+mCursor.getColumnName(i));
            }
            //
         SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list, mCursor, new String[]{ myHelper.col2_name }, new int[]{ R.id.listTextView1 });
         if(adapter!=null)System.out.println("adapter");
         mListView.setAdapter(adapter);     mListView.setOnItemClickListener
         (new AdapterView.OnItemClickListener()
         {       @Override
           public void onItemClick
           (AdapterView<?> arg0, View arg1, int arg2, long arg3)
           {
            System.out.println("onItemClick   arg2:"+arg2+"   arg3:"+arg3);
             mCursor.moveToPosition(arg2);
             _id = mCursor.getInt(0);
             System.out.println("In ItemClick:"+_id);
             mEditText.setText(mCursor.getString(1));
           }     });
         mListView.setOnItemSelectedListener
         (new AdapterView.OnItemSelectedListener()
         {
           @Override
           public void onItemSelected
           (AdapterView<?> arg0, View arg1, int arg2, long arg3)
           {
            System.out.println("onItemSelect   arg2:"+arg2+"   arg3:"+arg3);
             SQLiteCursor sc = (SQLiteCursor) arg0.getSelectedItem();
             _id = sc.getInt(0);
             System.out.println("ItemSelected:"+_id);
             mEditText.setText(sc.getString(1));
           }
           
           @Override
           public void onNothingSelected(AdapterView<?> arg0)
           {
           }
         });
        }