我試圖將項目位置從Fragment
發送到Activity
,但每次我在listView中選擇一個項目時都會收到invoiceId 0
。單擊ListView中的項目時獲取項目位置0
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;
在活動課
@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();
}
變化listview.getItemAtPosition(位置)的ToString()來position.toString –
@MayankBhatnagar你怎麼能叫成這樣? –