开发者

i can't add view to my viewflipper

开发者 https://www.devze.com 2023-04-04 01:41 出处:网络
Here\'s my code : public View anEpisode(String n, String i, String d){ View v; LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

Here's my code :

public View anEpisode(String n, String i, String d){
    View v;
    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = inflater.inflate(R.layout.episodedescription, null);

    TextView nameOfEpisode = (TextView) findViewById(R.id.episodedescriptionname);
    ImageView imageOfEpisode = (ImageView) findViewById(R.id.episodedescriptionimage);
    TextView descriptionOfEpisode = (TextView) findViewById(R.id.episodedescriptiondescription);

    nameOfEpisode.setText(n);
    descriptionOfEpisode.setText(d);
    createUrlImage(imageOfEpisode, i);

    return v;
}


    flipper.addView(anEpisode("test", "url image", "test description"));

my error is at this line :

    nameOfEpisode.setText(n);

Can you guys help me ? Maybe it's because of my 开发者_JAVA技巧inflater ?


I think you need to call findViewById on the results of inflater.inflate (notice the v.):

public View anEpisode(String n, String i, String d){
    View v;
    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = inflater.inflate(R.layout.episodedescription, null);

    TextView nameOfEpisode = (TextView) v.findViewById(R.id.episodedescriptionname);
    ImageView imageOfEpisode = (ImageView) v.findViewById(R.id.episodedescriptionimage);
    TextView descriptionOfEpisode = (TextView) v.findViewById(R.id.episodedescriptiondescription);

    nameOfEpisode.setText(n);
    descriptionOfEpisode.setText(d);
    createUrlImage(imageOfEpisode, i);

    return v;
}


flipper.addView(anEpisode("test", "url image", "test description"));
0

精彩评论

暂无评论...
验证码 换一张
取 消