英文:
How do i use getIntent().getSerializableExtra to retrieve data from the database
问题
I passed data from one activity to another and found this way to retrieve my get methods from my Shop class.
我将数据从一个活动传递到另一个活动,并找到了从我的Shop类中检索获取方法的方式。
Now I do not know how to proceed to insert these data into the TextViews or ImageViews in my DetailsActivity.
现在我不知道如何将这些数据插入到DetailsActivity中的TextViews或ImageViews中。
How would I go about doing this?
我应该如何操作?
This is my code so far:
这是我的代码:
public class DetailsActivity extends AppCompatActivity {
private FirebaseFirestore firebaseFirestore;
private RecyclerView FirestoreList;
private FirestoreRecyclerAdapter adapter;
TextView name_details;
TextView address_details;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
Shop shopModel = (Shop) getIntent().getSerializableExtra("shopModel");
name_details = findViewById(R.id.details_shopName);
address_details = findViewById(R.id.detail_addressDetails);
}
}
这是我的代码目前为止:
英文:
i passed data from one activity to another and found this way to retrieve my get methods from my Shop class.
now i do not know how to proceed to insert these data into the TextViews or ImageViews in my DetailsActivity.
how would i go about doing this?
this is my code so far:
public class DetailsActivity extends AppCompatActivity {
private FirebaseFirestore firebaseFirestore;
private RecyclerView FirestoreList;
private FirestoreRecyclerAdapter adapter;
TextView name_details;
TextView address_details;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
Shop shopModel = (Shop) getIntent().getSerializableExtra("shopModel");
name_details = findViewById(R.id.details_shopName);
address_details = findViewById(R.id.detail_addressDetails);
}
}
答案1
得分: 1
只需使用 setText
方法与您的 TextView
:
name_details.setText(shopModel.yourNameValue());
address_details.setText(shopModel.yourAddressValue());
对于 ImageView
,如果您的图像来自互联网,则需要一个图像下载库,例如 Picasso 或 Glide。
或者,如果您的图像来自 res/drawable
,则只需:
imageView.setImageResource(shopModel.yourImageResId());
英文:
Simply use setText
method with your TextView
name_details.setText(shopModel.yourNameValue());
address_details.setText(shopModel.yourAddressValue());
With ImageView
is a little bit complicate if your image is from Internet. You need a image downloading library like Picasso or Glide
or if your image is from res/drawable
, you just need to
imageView.setImageResource(shopModel.yourImageResId());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论