java部分代码:继承了ListActivity
@Override
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select); 
        final Button button_select=(Button)findViewById(R.id.button2);
        final Button button_update=(Button)findViewById(R.id.button3);
        final Button button_delete=(Button)findViewById(R.id.button4);
        final Button button_back=(Button)findViewById(R.id.button5);
        ArrayAdapter<String> aad = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, getData());        
        this.setListAdapter(aad);private List<String> getData(){ 
     database temp = new database(select.this, "sage");
     SQLiteDatabase db = temp.getWritableDatabase();
     Cursor cursor = db.query("user", new String[]{"name", "phone","address"}, null, null, null, null, null);
     List<String> data = new ArrayList<String>();  
    
     while(cursor.moveToNext())
             {
   
    data.add("名前:"+cursor.getString(cursor.getColumnIndex("name")));
             }
    
    
    
    
                   
         cursor.close();
     db.close();             
     return data;  
                               }  
protected void onListItemClick (ListView l, View v, int position, long id) 
     {
     System.out.print("Ok");
    
    }
=============================================================
xml代码:
<?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="vertical" >
    <ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:drawSelectorOnTop="false"/>
    <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1" >
            <TableRow >
                 <Button
                    android:id="@+id/button3"
                    android:layout_width="140px"
                    android:layout_height="wrap_content"
                    android:text="UPDATE" />
                    <Button
                    android:id="@+id/button4"
                    android:layout_width="140px"
                    android:layout_height="wrap_content"
                    android:text="DELETE" />
                 <Button
                    android:id="@+id/button2"
                    android:layout_width="140px"
                    android:layout_height="wrap_content"
                    android:text="SELECT" />
            </TableRow>      
    </TableLayout>
              <Button
                    android:id="@+id/button5"
                    android:layout_width="140px"
                    android:layout_height="wrap_content"
                    android:text="BACK" />    
</LinearLayout>
===============================================================================
我现在可以显示出所有数据库的数据,但是在点击视图里的记录时为什么不能调用onListItemClick方法在平台上打印出ok呢,请高手帮我看一下到底是那里出现了问题。我是初学者,麻烦各位说的详细些

解决方案 »

  1.   

     protected void onListItemClick (ListView l, View v, int position, long id) 里面加入一句super.onListItemClick(l, v, position, id);  
      

  2.   

    你是说出现错误,还是说不能看到“OK”,使用System.out.println("OK");你打印的消息不能在通常情况下的Eclipse console查看,你需要在DDMS的logcat中查看,标签是System.out
      

  3.   

    显示出来了,还有个问题想问一下,当我单击一条记录,要在onListItemClick方法里获得listview里该记录name字段的值,应该在该方法里怎样写呢
      

  4.   

    getData().get(position).get("name").toString()