gpt4 book ai didi

android - 错误 android.content.res.Resources$NotFoundException : File from xml type layout resource ID #0x102000a

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:29:46 26 4
gpt4 key购买 nike

嘿,我正在尝试为一个看起来像(并且大部分行为像)通话记录的列表设计,如下所示:

alt text

为此,我下载了源代码,并且正在研究它以了解实现它的类和 xml 文件。

我找到了这两个 xml 文件recent_calls_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="7dip">

<com.psyhclo.DontPressWithParentImageView
android:id="@+id/call_icon" android:layout_width="wrap_content"
android:layout_height="match_parent" android:paddingLeft="14dip"
android:paddingRight="14dip" android:layout_alignParentRight="true"

android:gravity="center_vertical" android:src="@android:drawable/sym_action_call"
android:background="@drawable/call_background" />

<include layout="@layout/recent_calls_list_item_layout" />

另一个是recent_calls_list_item_layout.xml:

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

<View android:id="@+id/divider"
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_toLeftOf="@id/call_icon"
android:layout_marginLeft="11dip"
android:background="@drawable/divider_vertical_dark"
/>

<ImageView android:id="@+id/call_type_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="4dip"
/>

<TextView android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/divider"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dip"
android:layout_marginLeft="10dip"

android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true"
/>

<TextView android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="36dip"
android:layout_marginRight="5dip"
android:layout_alignBaseline="@id/date"

android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
/>

<TextView android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/label"
android:layout_toLeftOf="@id/date"
android:layout_alignBaseline="@id/label"
android:layout_alignWithParentIfMissing="true"

android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall"
/>

<TextView android:id="@+id/line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/divider"
android:layout_above="@id/date"
android:layout_alignWithParentIfMissing="true"
android:layout_marginLeft="36dip"
android:layout_marginBottom="-10dip"

android:textAppearance="?android:attr/textAppearanceLarge"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center_vertical"
/>

我的 Activity 是这样的:

public class RatedCalls extends ListActivity {

private static final String LOG_TAG = "RecentCallsList";
private TableLayout table;
private CallDataHelper cdh;
private TableRow row;
private TableRow row2;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.recent_calls_list_item);
Log.i(LOG_TAG, "calling from onCreate()");

cdh = new CallDataHelper(this);
table = new TableLayout(getApplicationContext());
row = new TableRow(getApplicationContext());

startService(new Intent(this, RatedCallsService.class));
Log.i(LOG_TAG, "Service called.");
fillList();

}

public void onResume() {

super.onResume();
fillList();

}

public void fillList() {

List<String> ratedCalls = new ArrayList<String>();
ratedCalls = this.cdh.selectTopCalls();

setListAdapter(new ArrayAdapter<String>(RatedCalls.this,
android.R.id.list, ratedCalls));

ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_LONG).show();
}
});

}

然后我尝试在 android 模拟器上运行它,然后 LogCat 返回如下错误:

Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

所以在 recent_calls_list_item.xml 中我声明了:

<ListView android:id="@android:id/list" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_x="1px"
android:layout_y="1px">
</ListView>

现在有了这个声明,我尝试在模拟器中运行,但 LogCat 返回另一个错误:

android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x102000a

那么,我的问题是,为什么会这样?如果您有其他解决方案来实现这样的 View ,我正在尝试。

谢谢。

最佳答案

我遇到了同样的问题。我是这样设置文本的:

statusView.setText(firstVisiblePosition);

问题是 firstVisiblePosition 是一个整数。编译器没有提示。修复它

statusView.setText(""+firstVisiblePosition);

关于android - 错误 android.content.res.Resources$NotFoundException : File from xml type layout resource ID #0x102000a,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4658590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com