0

タグで ImageView を見つけようとしています。ImageView にタグを割り当てましたが、findViewWithTag を実行しようとすると null が返されます。addChilder を使用してチャイルダーをビューに追加する必要があることを読みましたが、ビューにはこの機能がありません。誰かが私にこれを行う方法を説明できますか?

ImageView principal = (ImageView) findViewById(R.id.imagen_home_0);
    principal.setTag("principal");

コンテキストを渡す他のクラス(AsyncTask)で

        View noMiembros = new View(context);

        ImageView er = (ImageView) noMiembros.findViewWithTag("principal");
        er.setImageBitmap(result);
4

3 に答える 3

4

Activity を AsyncTask に渡し、次を使用します。

ImageView principal = (ImageView) passedActivity.findViewById(R.id.imagen_home_0);

または、次のように Context からインフレータを取得します。

LayoutInflater inflater = LayoutInflater.from(context);
View row = inflater.inflate(R.layout.your_viw_that_contains_that_image, parent, false);

ImageView principal = (ImageView) row.findViewById(R.id.imagen_home_0);

//or by tag 
principal = (ImageView) row.findViewWithTag("principal");

幸運をお祈りしています。

于 2013-06-21T10:58:54.147 に答える
4

新しいビューを呼び出しfindViewWithTagています。noMiembros

findViewWithTag到達しようとしている ImageView の親を呼び出す必要があります。

ただし、AsyncTask 内から ImageView を取得する場合は findViewById(R.id.imagen_home_0) 、Activity を呼び出すだけです。

于 2013-06-21T10:59:37.767 に答える
0

私はあなたが…それらの2つのタグを間違えていると信じています。

setTag()ビューに任意のオブジェクトをアタッチできますが、XML タグは文字列にすぎfindViewByTagません。任意のオブジェクトである可能性があるため、コードを介してアタッチされたタグではなく、XML を介して渡されたタグと一致しようとすると思います。

principalimageView を asyncthread に渡さないのはなぜですか?

于 2013-06-21T10:50:48.543 に答える