Нажмите listView Item Error @ ID # 0x5? - PullRequest
0 голосов
/ 03 мая 2011

Я получаю сообщение об ошибке «Исключение ресурсов не найдено: строковый идентификатор ресурса # 0x5. Я знаю, что это связано с i.putExtra (...). Я пытаюсь извлечь строку из столбца БД gotoURL, чтобы передать строку URL-адреса из listItem в ListView в Activity WebView. Любая помощь PLZ! Thnx!

Я моя активность:

    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";
}

}

1 Ответ

1 голос
/ 03 мая 2011

Проблема может быть в onItemClickListner:

i.putExtra ("url", getString (cursor.getColumnIndexOrThrow ("gotoURL")));

Вы запрашиваете columnindex (целое число), используйте его в качестве входных данных для Context.getString (), который ожидает, что это будет (существующий) ID ресурса. По вашей ошибке я могу догадаться, что columnIndex для "gotoURL" равно 5 и такого идентификатора ресурса не существует ...

Я полагаю, что вы действительно хотите указать в намерении строковое значение для столбца "gotoURL", как вы делаете это в адаптере?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...