这是我的代码:
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?
答案 0 :(得分:2)
我认为你需要在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"));