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
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.
于 2012-11-03T08:00:35.530 に答える
0

ここにエラーを貼り付けてください。値が見つからないか、クラスキャストの例外が原因で、私は私かもしれないと思います。

于 2012-11-05T13:50:13.697 に答える
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 に答える