簡體   English   中英

在從適配器向活動傳遞意圖的數據時獲取空值

[英]Getting Null Values while passing data with intent from adapter to activity

這可能是一個非常基本的問題,但我找不到答案。

我需要從RecyclerView傳遞數據,但是當我在相關活動中檢查數據時,數據為null。

mvHolder.barcode.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent s = new Intent(context, SummaryActivity.class);
        s.putExtra("SUMMARY",sp.getDATA().get(i).getId_summary()); // data is not null
        context.startActivity(s);
    }
});

這就是我嘗試實現的方法:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    strBarcode = extras.getString("SUMMARY");
    // and get whatever type user account id is
}

但是當我調試它時,結果發現strBarcode為null。 我不知道問題出在哪里,我想我的代碼也應該可行。 請幫我

Intent data = getIntent();
if (data != null) {
    strBarcode = data.getStringExtra("SUMMARY");
    // and get whatever type user account id is
}

檢查getIntent().hasExtra("SUMMARY") returns true 如果是這樣,請確保sp.getDATA().get(i).getId_summary()返回String

可能有多余的東西,但是您嘗試將其作為String獲取,並且它可能具有不同的類型。

Intent data = getIntent();
if (data != null) {
   int strBarcode = data.getIntExtra("SUMMARY");
}

請試試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM