I am trying to send an item position from a Fragment
to an Activity
, but I always get invoiceId 0
every time I select an item in listView.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent seperateView = new Intent(rootView.getContext(),SeperateViewForDeliveryList.class);
seperateView.putExtra("invoiceId", listView.getItemAtPosition(position).toString());
startActivity(seperateView);
}
});
listView.setAdapter(deliveryListAdapter);
return rootView;
In activity class
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seperate_view_for_delivery_list);
invoiceId = getIntent().getExtras().getString("invoiceId");
Toast.makeText(this, "invoiceID " + invoiceId, Toast.LENGTH_SHORT).show();
}
We can also pass integer value in an
Intent
. Try this: