2014-06-15 53 views
0

我目前正在嘗試找到一種方法來獲得諸如「東西,東西,這個,」這樣的輸入,然後能夠將每個單獨的部分分割成不同的值,以便我可以將它們用於不同的東西。輸入分割方法

例如將它們放置到它們自己的TextView位置或根據輸入設置計時器,但仍然能夠完全使用其他信息。

我在使用eclipse之前就已經看到了這一點,我目前正試圖從他們那裏獲取代碼,但到目前爲止我還沒有得到任何迴應。

感謝您提前提供任何幫助,我有一種感覺,這將是一個艱難的事情。

編輯: 我想用它來編輯結果

<TextView 
    android:id="@+id/LocationFixed" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/location" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/LocationResult" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/locationResult" /> 

<TextView 
    android:id="@+id/TimeFixed" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/time" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/TimeResult" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/timeResult" /> 

<TextView 
    android:id="@+id/CostFixed" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/cost" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/CostResult" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/costResult" /> 

回答

1

的值可以使用String類的split方法使用的分隔符是一個逗號到您的字符串分隔。

例如:

String s = "stuff,things,this,that"; 
String [] s2 = s.split(","); 
System.out.println("1 list" + s2[0]); //result stuff 
System.out.println("2 list" + s2[1]); //result things 
System.out.println("3 list" + s2[2]); //result this 
System.out.println("4 list" + s2[3]); //result that 

獲得在onCreate()

TextView t = (TextView)findViewById(R.id.LocationFixed); //will get the textview from the layout 
t.setText("set The text"); //set the textview text 
+0

視圖參考

我將要做的調用每個不同的人將它們應用到不同的佈局TextViews 。 (給我一分鐘上傳我的意思,如果這將有助於代碼) –

+0

@Tehjohn editted。與其他textviews一樣 –

+0

因此,要使'LocationResult'「this」,我會使用't.setText(s2 [2]);'? –