Java 将数据绑定到活动中
如何将数据绑定到我的活动中,以便每个项目都具有正确的文本。我是按照教程,但它只显示了如何加载图像。我正在尝试将item.getTitle()放入(titleorg);但是有一些错误 这是我的活动细节Java 将数据绑定到活动中,java,android,android-studio,Java,Android,Android Studio,如何将数据绑定到我的活动中,以便每个项目都具有正确的文本。我是按照教程,但它只显示了如何加载图像。我正在尝试将item.getTitle()放入(titleorg);但是有一些错误 这是我的活动细节 public class OrgDetails extends AppCompatActivity { ImageView imgorg; TextView titleorg, descorg; @Override protected void onCreate(Bundle savedInsta
public class OrgDetails extends AppCompatActivity {
ImageView imgorg;
TextView titleorg, descorg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_org_details);
this.imgorg = findViewById(R.id.item_org_logo);
this.titleorg = findViewById(R.id.item_org_title);
this.descorg = findViewById(R.id.item_org_description);
Org item = (Org) getIntent().getExtras().getSerializable("orgObject");
loadOrgData(item);
}
private void loadOrgData(Org item) {
Glide.with(this).load(item.getDrawableResource()).into(imgorg);
}
那是我的模特
public class Org implements Serializable {
private String title, description;
private int drawableResource;
public Org(int drawableResource) {
this.drawableResource = drawableResource;
}
public Org(String title, String description, int drawableResource) {
this.title = title;
this.description = description;
this.drawableResource = drawableResource;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getDrawableResource() {
return drawableResource;
}
public void setDrawableResource(int drawableResource) {
this.drawableResource = drawableResource;
}
您应该在问题正文中共享代码,而不是上载图片。这似乎可以(对于标题):
titleorg.setText(item.getTitle())
-使用组织标题设置标题文本视图。(在构造函数中设置了项之后,当然是最后一行了)。这对我很有效,谢谢