如何使用getIntent().getSerializableExtra从数据库中检索数据。

huangapple go评论84阅读模式
英文:

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,如果您的图像来自互联网,则需要一个图像下载库,例如 PicassoGlide

或者,如果您的图像来自 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());

huangapple
  • 本文由 发表于 2020年8月7日 10:46:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63294452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定