2017-12-28 11 views
2

私はrecyclerviewのカードのonClick()データベースからIDを取得し、このIDに関連する詳細が表示される次のアクティビティでこのIDを渡します。私が取得しているIDは間違っているため、間違った詳細が表示されます。助けてください。recyclerviewのonClickでインテントを渡す

@Override 
public void onBindViewHolder(final ViewHolder holder, final int position) { 
    ListInvoice listInvoice = listInvoices.get(position); 

    holder.invoice_noText.setText(listInvoice.getInvoice_no()); 
    Picasso.with(context).load(listInvoice.getLogo()).resize(180,80).into(holder.imageText); 
    holder.dateText.setText(listInvoice.getCreated_at()); 
    holder.cc_codeText.setText(listInvoice.getCc_code()); 
    holder.nameText.setText(listInvoice.getName()); 
    holder.test_priceText.setText(listInvoice.getTest_price()); 
    id = listInvoice.getId(); 
    holder.relativeLayout.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      context = v.getContext(); 
      int a = holder.getAdapterPosition(); 
      passData(a); 

     } 
    }); 

} 

private void passData(int a) { 

    Intent intent = new Intent(context,InvoiceDetails.class); 
    intent.putExtra("id", ""+id); 
    context.startActivity(intent); 
} 

そして、これがデータを受信し、この

holder.relativeLayout.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
    Intent intent = new Intent(context,InvoiceDetails.class); 
    intent.putExtra("id", ""+ listInvoice.getId()); 
    context.startActivity(intent); 

    } 
}); 

を試してみて、私は次のアクティビティに

Intent intent = getIntent(); 
    id = intent.getStringExtra("id"); 
    Toast.makeText(getApplicationContext(),id,Toast.LENGTH_LONG).show(); 
    loadInvoice(id); 

答えて

3

この

holder.relativeLayout.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     id = listInvoice.getId(); 
     passData(id); 

    } 
}); 

private void passData(int id) { 

    Intent intent = new Intent(context,InvoiceDetails.class); 
    intent.putExtra("id", ""+id); 
    context.startActivity(intent); 
} 
+0

ありがとうございます。その仕事 –

+0

@AparnaMutnalkarそれを聞いてうれしい..幸せなコーディング..あなたは私の答えを受け入れることができます。 –

+0

なぜdownvote .. !! @AparnaMutnalkarのために既に働いています。 –

0

を取得しています方法です:

Intent intent = getIntent(); 
id = intent.getStringExtra("id"); 
Toast.makeText(getApplicationContext(),id,Toast.LENGTH_LONG).show(); 
loadInvoice(id); 
+0

のクリックされたアイテムのIDを渡す必要があり、これを試してみてください試してみてください? – R2R

+0

が機能しません。以前と同じ出力 –

+0

私の編集した回答を試してください – R2R

1

は、あなたはそれがなぜdownvote間違っているrecyclerview

private void passData(int a) { 

    Intent intent = new Intent(context,InvoiceDetails.class); 
    intent.putInt("id", a); 
    context.startActivity(intent); 
} 

GETのID

Bundle extras = getIntent().getExtras(); 
int id = extras.getInt(YOUR_KEY); 
関連する問題