简体   繁体   English

无法访问我在ListActivity上的R布局

[英]Can't access my layout of R on a ListActivity

I've got a Question. 我有一个问题。 I have a ListActivity in which i can't access over R, my own layout that i wrote for it, what am I doing wrong. 我有一个ListActivity,其中无法访问R(我为此写的布局),我在做什么错。

So here's the Layout Code (list_layout.xml): 因此,这是布局代码(list_layout.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

      <TextView android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/nofilter"/>

</LinearLayout>

Now i can't bind that Layout to my ListActivity over setContentView(R.layout.list_layout); 现在,我无法通过setContentView(R.layout.list_layout);将该布局绑定到我的ListActivity setContentView(R.layout.list_layout); Here's some more Code about the ListActivity: 这是有关ListActivity的更多代码:

package de.retowaelchli.filterit.stats;

import java.util.ArrayList;
import java.util.List;

import de.retowaelchli.filterit.database.ADFilterDBAdapter;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;

public class CreatedADFilters extends ListActivity {

    //Variablen deklaration
    private ADFilterDBAdapter mDbHelper;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list_layout);

      }  
    }

Wham am I doing wrong? 我做错了什么?

Best Regards 最好的祝福

safari 苹果浏览器

NOTES: 笔记:

I tried to clean my Project, it didnt work. 我试图清理我的项目,但没有成功。

Make sure that the import of the R class is from your application and not com.android.R. 确保R类的导入是从您的应用程序而不是com.android.R。 Sometimes when you use Eclipse's auto import it will import the wrong one... 有时,当您使用Eclipse的自动导入功能时,它会导入错误的内容...

use layout file like : 使用如下布局文件:

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

This is a ListActivity example. 是一个ListActivity示例。

try to use LayoutInflater. 尝试使用LayoutInflater。

LayoutInflater mInflater; LayoutInflater mInflater; mInflater.inflate(R.layout.custom_row_view, null); mInflater.inflate(R.layout.custom_row_view,null);

Might be worth cleaning your project. 可能值得清理您的项目。 If you're using eclipse, go to: Project > Clean... 如果您使用的是eclipse,请转到:“项目”>“清理...”。

You must have one ListView in your project Layout file. 您的项目布局文件中必须具有一个ListView。 And also see for delete android.R if it is auto imported there.If you are not using listview then yru exetnding ListActivty.Extend Activity only. 还要查看是否删除android.R如果它是自动导入的。如果您不使用listview,则您仅显示ListActivty.Extend Activity。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM