【发布时间】:2011-05-03 00:23:37
【问题描述】:
我收到错误消息“找不到资源异常:字符串资源 ID #0x5。我知道它与 i.putExtra(...) 有关。我正在尝试从数据库列“gotoURL”中提取一个字符串,以将一个 URL 字符串从我的 ListView 中的 listItem 传递到 WebView Activity。任何帮助PLZ!谢谢!
我是我的活动:
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
// @Override
public void onItemClick(AdapterView<?> a, View v, int position,long id)
{
Object o = lv.getItemAtPosition(position);
Toast.makeText(List_AC.this, "Clicked!", Toast.LENGTH_LONG).show();
Intent i = new Intent(List_AC.this, DocView.class);
Cursor cursor = Adapter_AC.dataCursor;
i.putExtra("url", getString(cursor.getColumnIndexOrThrow("gotoURL")));
startActivity(i);
}
});
适配器:
public class Adapter_AC extends SimpleCursorAdapter {
static Cursor dataCursor;
private LayoutInflater mInflater;
public Adapter_AC(Context context, int layout, Cursor dataCursor,
String[] from, int[] to) {
super(context, layout, dataCursor, from, to);
this.dataCursor = dataCursor;
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.label);
holder.text2 = (TextView) convertView.findViewById(R.id.listTitle);
holder.text3 = (TextView) convertView.findViewById(R.id.caption);
holder.text4 = (TextView) convertView.findViewById(R.id.dummy);
holder.text4.setVisibility(View.GONE);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
dataCursor.moveToPosition(position);
int label_index = dataCursor.getColumnIndex("label");
String label = dataCursor.getString(label_index);
int title_index = dataCursor.getColumnIndex("title");
String title = dataCursor.getString(title_index);
int description_index = dataCursor.getColumnIndex("description");
String description = dataCursor.getString(description_index);
int goto_index = dataCursor.getColumnIndex("gotoURL");
String gotoURL = dataCursor.getString(goto_index);
holder.text1.setText(label);
holder.text2.setText(title);
holder.text3.setText(description);
holder.text4.setText(gotoURL);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
TextView text3;
TextView text4;
protected static final String KEY_TITLE = "text4";
}
}
【问题讨论】:
-
究竟是哪一行引发了异常?
标签: android listview webview adapter onitemclicklistener