关于onListItemClick问题

lxz_jxmz1125 2011-12-07 09:39:36
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呢,请高手帮我看一下到底是那里出现了问题。我是初学者,麻烦各位说的详细些
...全文
220 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
安卓机器人 2011-12-07
  • 打赏
  • 举报
回复
你是说出现错误,还是说不能看到“OK”,使用System.out.println("OK");你打印的消息不能在通常情况下的Eclipse console查看,你需要在DDMS的logcat中查看,标签是System.out
lxz_jxmz1125 2011-12-07
  • 打赏
  • 举报
回复
还是不好用
小王爷 2011-12-07
  • 打赏
  • 举报
回复
protected void onListItemClick (ListView l, View v, int position, long id) 里面加入一句super.onListItemClick(l, v, position, id);
小王爷 2011-12-07
  • 打赏
  • 举报
回复
大哥,结贴吧,给点分啊,大家都不容易
小王爷 2011-12-07
  • 打赏
  • 举报
回复
getData().get(position).get("name").toString()
lxz_jxmz1125 2011-12-07
  • 打赏
  • 举报
回复
显示出来了,还有个问题想问一下,当我单击一条记录,要在onListItemClick方法里获得listview里该记录name字段的值,应该在该方法里怎样写呢

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧