私はアンドロイドで遊びたかったので、既存のいくつかを取り、それを変更しました。これは、デフォルト設定を使用し、新しいファイルを使用せずに 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>
ただし、エミュレーターでアプリを実行すると、この大きなエラーリストが表示されます
なぜこれが起こっているのか、そしてそれを修正する方法を誰かが理解するのを手伝ってくれませんか?