我有一个 ArrayAdapter,它的 getView 用数据设置列表视图中的项目。当我单击列表视图中的一行时,我想开始另一个活动(我可以这样做),但向该活动发送一些数据以呈现在另一个视图中。
如何在 onItemClick 方法中使 getView 中的数据可访问?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rotarowlayout, parent,
false);
TextView startTime = (TextView) rowView
.findViewById(R.id.rowstarttime);
TextView duration = (TextView) rowView
.findViewById(R.id.rowduration);
TextView status = (TextView) rowView.findViewById(R.id.rowstatus);
TextView name = (TextView) rowView.findViewById(R.id.rowclientname);
TextView actualTimeIn = (TextView) rowView.findViewById(R.id.rowactualtimein);
TextView actualTimeOut = (TextView) rowView.findViewById(R.id.rowactualtimeout);
String record = list.get(position).toString();
String[] itemsInRecord = record.split(",");
Log.e(TAG, "itemin record = " + itemsInRecord.length);
String[] recordItem = new String[itemsInRecord.length];
for (int x = 0; x < itemsInRecord.length; x++) {
recordItem[x] = itemsInRecord[x];
}
//set date above listview
textViewDate.setText("Rota For " + recordItem[0].substring(1, 11));
String withoutBraket = recordItem[0].substring(11);
String withoutSecs = withoutBraket.substring(0, 6);
Log.e(TAG, "recordItem = " + recordItem[2]);
String _statusString = recordItem[2].toString().trim();
if(_statusString.equalsIgnoreCase("Completed")){
statusField = "c";
}else if(_statusString.equalsIgnoreCase("NCR")){
statusField = "NCR";
}else if(_statusString.equalsIgnoreCase("Waiting")){
statusField = "W";
}
Log.e(TAG, "statusField = " + statusField);
startTime.setText(withoutSecs+" " );
duration.setText( recordItem[1]+" mins ");
status.setText( statusField);
name.setText( " " + recordItem[3] + recordItem[4]);
callID = recordItem[5];
// needName = recordItem[6];
actualTimeIn.setText("This call was completed at " + recordItem[6] + " - ");
if( ! recordItem[7].toString().trim().equalsIgnoreCase( "]")){
String stripBracket = recordItem[7].toString().trim();
Log.e(TAG, "stripBracket = " + stripBracket);
String stripBracket2 = stripBracket.substring(0,5);
Log.e(TAG, "SB after split = " + stripBracket2 );
actualTimeOut.setText(stripBracket2);
}
return rowView;
}
.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.e(TAG, "inside onItemClick");
Intent i = new Intent(GetRota.this, someOtherActivity.class);
i.putsomedata;
startActivity(i);
}