2012-11-03 42 views
0

我特林加入字符串數組中的所有值,但它不工作:如何在字符串數組中添加通過用戶輸入的值?

public class Info extends Activity { 
private static final String TAG = "Info"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.info); 

    Intent myIntent = getIntent(); 
    Bundle b = myIntent.getExtras(); 
    String choice = b.getString("choice"); 
    String fname = b.getString("fname"); 
    String lname = b.getString("lname"); 
    String add = b.getString("add"); 
    String coun = b.getString("coun"); 
    String pro = b.getString("pro"); 
    String pcode = b.getString("pcode"); 

    Log.i(TAG,"selection: " + choice); 
    TextView textView = (TextView) findViewById(R.id.showmeText); 
    textView.append(": " + choice); 
    TextView textView1 = (TextView) findViewById(R.id.fname); 
    textView1.append(" " + fname); 
    TextView textView2 = (TextView) findViewById(R.id.lname); 
    textView2.append(" " + lname); 
    TextView textView3 = (TextView) findViewById(R.id.address1); 
    textView3.append(" " + add); 
    TextView textView4 = (TextView) findViewById(R.id.pro); 
    textView4.append(" " + pro); 
    TextView textView5 = (TextView) findViewById(R.id.country1); 
    textView5.append(" " + coun); 
    TextView textView6 = (TextView) findViewById(R.id.pcode); 
    textView6.append(" " + pcode); 

} 

我ListView中嘗試了這些所有的值,但這些不工作,因爲我是在ListView.Can您加入所有的TextView請幫助我如何在String數組中添加這些列表?

回答

1
Crete a ListView in your UI Deisgn layout xml. 


<ListView android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
         android:id="@+id/choice_list" 
      android:focusable="false" 
        android:scrollbarStyle="outsideOverlay"> 







Step1 : Create a String Array ex: String[] myStringArray. 

Step 2: Push all the string values into Array. 
Step 3 : in your activity get the reference for listview (choice_list) 

Ex: 


ListView choiceListView = (ListView)findviewById(R.layout.choice_list) 

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), 
        android.R.layout.simple_dropdown_item_1line, myStringArray); 

choiceListView .setAdapter(適配器);

That is all to see the out put as list view in normal activity. You don't need ListActivity , but can use this in normal activity too. The above is the solution for any activity which has a listview as a component in it. 

If you like this please vote for me. 
+0

如何推送字符串數組中的所有值,我具有不同變量中的所有值。請幫助我。我被困在這個問題中... – user1050667

1

只是試試這個

public class ArrayAdapterDemo extends ListActivity { 
    TextView selection; 

    "silly", "list" }; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     item.add(choice); 
setListAdapter(new ArrayAdapter<String>(
     this, 
     android.R.layout.simple_expandable_list_item_1, 
     items)); 
selection=(TextView)findViewById(R.id.selection); 
    } 
+0

我有6-7個字符串如何添加所有這些...你能告訴什麼是項目..它是字符串變量或字符串數​​組什麼是什麼是我們聲明這個項目..? – user1050667

0
String[] myStringArray = new String[7]; 
myStringArray[0] = choice; 
myStringArray[1] = fname; 
...... 
myStringArray[7] = pcode ; 

Or you want to display all the text in a single textview. Your question is not clear. 

I hope if its about pushing the values into the array then the above holds good. 
+0

我試過同樣的事情,但是當我在模擬器上運行此應用程序時,它顯示我的錯誤信息我的意思是它不運行。 – user1050667

+0

請在這裏輸入錯誤。我想我可能會因爲價值缺失或類拋出異常 – kumar

0

請粘貼在這裏的錯誤。我想我可能會因爲缺少價值或者類別轉換異常。

+0

它顯示我的頁面加載錯誤它告訴我**應用程序動畫(process com.example.animation)已意外停止。請再試一次。** – user1050667

+0

我是通過菜單項傳遞所有的值是否可以......? – user1050667

相關問題