0

リストビューアイテムに次のレイアウトを使用しています。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://scheme.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:textSize="18sp"
    android:minHeight="40sp"
    />

しかし、logcat java.lang.RuntimeException でエラーが発生しています ... layout_width 引数を指定する必要があります。

私のmain.xmlは

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget28"
    android:background="#ff000033"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="70px"
        android:layout_height="30px"
        android:paddingLeft="2px"
        android:paddingTop="2px"
        android:background="@drawable/ic_launcher"
     ></ImageView>

    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

これは私のアクティビティのonCreateコードです

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    context=this.getApplicationContext();
    this.setTitle("NP Headline News");

    myListView=(ListView)findViewById(R.id.myListView);
    myListView.setOnItemClickListener(new OnItemClickListener(){

            @Override
        public void onItemClick(AdapterView<?> arg0, View v, int index,long id) {
                // TODO Auto-generated method stub
                String urlAddress=urlAddresses[index];
                String urlCaption = urlsCaptions[index];
            }

    });

  int layoutId=R.layout.simple_list_item_1;
   // int layoutId=android.R.layout.simple_list_item_1;
    aa = new ArrayAdapter<String>(this,layoutId,this.urlsCaptions);

    myListView.setAdapter(aa);
}

android.R.layout.simple_list_item_1 を使用すると、すべてが正常に機能するため、それは私の simple_list_item_1 に関連するものだと思います

4

3 に答える 3

2

エラーがクリアされたレイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:textSize="18sp"
    android:minHeight="40sp"

    />

エラーに含まれるコードと上記のコードを区別できますか。

何かをコーディングしている間は緊張したり衝動に駆られたりしないでほしいと思います。

これらのタイプのエラーについては、DDMS を使用して自分でデバッグすることができます。コードは非常に単純で、正しく表示されるためです。

そして、以前の回答についてのいくつかの言葉:

ファイル内でのみaTextViewまたは anyを宣言する必要がないやつ。ViewLayout

また、Viewで一人で座ることができCanvasます。

また、問題は、、"fill_parent"および"match_parent"何かによるものではありません。

私はあなたのエラーの理由を説明するのにこれだけの時間を費やしているので、あなたは今も緊張していると思います.

どうぞ、

エラーは、単に次の行で、

xmlns:android="http://schemas.android.com/apk/res/android"

scheme上記の行では、 の代わりに誤って入力しましたschemas

それがエラーです。

したがって、時制なしでコードを見れば、簡単に取得できると述べただけです。

xmlnsandroid: 名前空間を示します。これは、プレフィックス付きの属性を価値のあるものにするために適切である必要があります。

ご理解いただき、回答が役立つことを願っています。

于 2012-04-16T14:20:37.697 に答える
0

独自の TextView を使用しているため、LinearLayout を追加できるため、Layout の下に TextView を配置する必要があります。

<?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 xmlns:android="http://scheme.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:textSize="18sp"
    android:minHeight="40sp"
    />
</LinearLayout>
于 2012-04-16T13:56:04.327 に答える
0

問題は別の何かから来ていると思います。

カスタム アイテム ビューを実行していますが、標準の AdapterView を使用しています。

標準的な arrayAdapter の場合、期待される構造を満たす必要があります。

または、独自の ArrayAdapter を構築し、専用の getView を提供します

Android カスタム リストビュー

于 2012-04-16T14:18:49.120 に答える