我想玩android,所以我拿了一些我现有的并修改了它。它是一个主从应用程序,在 Eclipse 中使用默认设置生成,没有新文件。我获取了位于 com.. 中的 ItemDetailFragment.java 的代码并对其进行了修改,以便在屏幕上 (0,0) 处绘制一些测试
这是我修改的代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item_detail,
container, false);
//customImageView custom = (customImageView) inflater.inflate(R.layout.fragment_item_detail, container, false);
// Show the dummy content as text in a TextView.
if (mItem != null) {
//((ImageView) rootView.findViewById(R.id.item_detail_)).setImageResource(R.drawable.ic_launcher);
((customImageView) rootView.findViewById(R.id.item_detail__)).invalidate();
}
return rootView;
}
private class customImageView extends View {
/*To clarify I added this class myself b/c the android developer guide on Canvas and Drawables says to*/
public customImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawText("Some Example Text", 0, 0, new Paint());
}
}
}
哦,这是我的 /res/layout/fragment_item_detail.xml 声明
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/item_detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textIsSelectable="true" />
<!-- Autogenerated -->
<ImageView
android:id="@+id/item_detail_"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- android:src="@drawable/android" /> -->
<!-- I added this in -->
<customImageView
android:id="@+id/item_detail__"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- This is the relevant part, I added this in -->
</LinearLayout>
但是,当应用程序在模拟器上运行时,我会得到这个大的错误列表
有人可以帮我理解为什么会这样,以及如何解决吗?