我有一个列表视图,其中有四到五列。列表视图的值是通过数据库查询分配的。列表视图是使用 SimpleCursorAdapter 创建的。我正在尝试获取列表视图第一列的值......但我无法检索它。我怎么做???这是我的自定义适配器
private class MyCursorAdapter extends SimpleCursorAdapter
{
@SuppressWarnings("deprecation")
public MyCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to,int flags) {
super(context, layout, c, from, to);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//get reference to the row
View view = super.getView(position, convertView, parent);
//check for odd or even to set alternate colors to the row background
if(position % 2 == 0){
view.setBackgroundColor(Color.rgb(238, 233, 233));
}
else {
view.setBackgroundColor(Color.rgb(255, 255, 255));
}
return view;
}
}
这是我将适配器分配给列表视图的地方
MyCursorAdapter myDataAdapter=new MyCursorAdapter(this,R.layout.list_row_layout,cursor, columns, to, 0);
listView=(ListView)findViewById(R.id.listView1);
listView.addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null, false));
listView.setAdapter(myDataAdapter);
这是 onclick 监听器
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
//View view=
String ttsl_can=(( listView.getItemAtPosition(position).toString()));
Toast.makeText(PendingActivity.this, ttsl_can, Toast.LENGTH_LONG).show();
}
});
通过单击列表视图 m 的特定行,得到响应为android.database.SQLiteCursor@40d2f13d
我如何将响应作为我单击的任何行的第一列的值?我在我的代码中做了什么改变来实现这一点???
请帮忙!!提前致谢!!