gpt4 book ai didi

java - 我无法将 View 添加到我的 viewflipper

转载 作者:行者123 更新时间:2023-12-02 08:11:26 25 4
gpt4 key购买 nike

这是我的代码:

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"));

我的错误在这一行:

    nameOfEpisode.setText(n);

你们能帮我吗?也许是因为我的充气机?

最佳答案

我认为您需要对 inflater.inflate 的结果调用 findViewById (注意 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"));

关于java - 我无法将 View 添加到我的 viewflipper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7367668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com