我想在String Array中添加所有值,但它不起作用:
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。可以帮助我如何在String数组中添加这些列表?
答案 0 :(得分: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);
}
答案 1 :(得分: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(adapter);
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.
答案 2 :(得分: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.
答案 3 :(得分:0)
请在此处粘贴错误。我想我可能是因为价值缺失或类别转换异常。