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 中添加了所有 Textview。你能帮我如何在字符串数组中添加这些列表吗?

4

4 回答 4

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); 
   }
于 2012-11-03T07:34:48.987 回答
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);

选择列表视图.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.
于 2012-11-03T08:00:35.530 回答
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.
于 2012-11-05T07:42:35.587 回答
0

请在此处粘贴错误。我想我可能是因为缺少值或类转换异常。

于 2012-11-05T13:50:13.697 回答