我正在使用getItemIdAtPosition()來獲取Sqlite數據庫中記錄的Basecoulmns id。Android中的getItemIdAtPosition()問題?
的代碼如下:
protected void onListItemClick(ListView l, View v, int position, long id) {
Cursor cursor = managedQuery(Constants.CONTENT_URI,
PROJECTION, BaseColumns._ID + "="
+ l.getItemIdAtPosition(position), null, null);
}
但其不正確檢索的ID。這種方法在設置適配器或創建數據庫時依賴於某些東西?我不知道。爲什麼它顯示了listview的位置。任何想法?
編輯:
爲getView代碼mehod:
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.brutube_videos, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView
.findViewById(R.id.vdo_text1);
holder.text2 = (TextView) convertView
.findViewById(R.id.vdo_text2);
holder.text3 = (TextView) convertView
.findViewById(R.id.vdo_rate_text);
holder.icon = (ImageView) convertView
.findViewById(R.id.vdo_icon);
convertView.setTag(holder);
} else {
holder.text1 = (TextView) convertView
.findViewById(R.id.vdo_text1);
holder.text2 = (TextView) convertView
.findViewById(R.id.vdo_text2);
holder.text3 = (TextView) convertView
.findViewById(R.id.vdo_rate_text);
holder.icon = (ImageView) convertView
.findViewById(R.id.vdo_icon);
}
if (!mBusy) {
try {
Log.v("getview", "" + (position) + " - " + VAL3[position]);
holder.icon.setImageBitmap(BitmapFactory
.decodeStream(new URL(VAL3[position])
.openConnection().getInputStream()));
notifyDataSetChanged();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
holder.icon.setTag(null);
} else {
holder.icon.setImageResource(R.drawable.no_video_icon);
// Non-null tag means the view still needs to load it's data
holder.icon.setTag(this);
}
holder.text1.setText(VAL1[position]);
holder.text2.setText(VAL2[position]);
holder.text3.setText(VAL4[position] + " Ratings");
return convertView;
}
ThanX的回覆。你能用一些示例代碼來解釋它嗎?我無法完全理解你。 – Praveen 2010-05-31 18:00:35
當然,你能解釋一些關於你如何填寫你的清單嗎?你是從光標填充它嗎?如果是這樣,你使用SimpleCursorAdapter嗎? – m6tt 2010-05-31 18:09:33
不,我只是擴展基礎適配器。如何設置它? – Praveen 2010-05-31 18:17:40