2011-11-22 19 views

risposta

21

che restituirà la segmento del percorso con l'indice '1'.

Con questo, voglio dire, Se si dispone di content://com.myapp/first/second/third/ restituirà 'secondo'. get (2) restituirà 'terzo' e così via ...

+0

Divide l'intera stringa guardando il '/'? –

+0

Suppongo che ignorerebbe il ": //", ma sì, penso di sì. – MrZander

+0

Inoltre, salterà un percorso vuoto come '/ first // third /' – MrZander

1

Non ci ha detto che cosa di Uri tipo è, ma se si tratta di un oggetto Uri poi guardando il Android URI Docs possiamo vedere che getPathSegments restituisce una lista di stringhe. Quindi chiamando get(1) restituisce il 2 ° elemento nell'elenco restituito da getPathSegments().

Il codice potrebbe essere riscritta come segue:

List<String> segments = ui.getPathSegments(); 
String secondItem = segments.get(1); 
+0

Divide l'intera stringa guardando il '/'? –

1

Nel mio test, chiamando getPathSegments sul Uri qui sotto:

content://example.cs454.sunshine/weather/90015/1463468400000 

ha prodotto un elenco con questi contenuti:

index 0 weather 
index 1 90015 
index 2 1463468400000