微調框有一些問題。根據我的日期,我必須添加到TableRow
a TextView
與EditText
或Spinner
。我必須在Spinner中顯示的數組有點長。我測試了我的代碼與短文本的數組,它看起來像這樣:微調框不能正常工作
這裏的一個問題是,微調不是fill_parent
。
如果我把我的數組微調器,它看起來是這樣的:
在這種情況下,微調看起來並不像一個微調和EditText上是不可見的了。當我選擇了微調,看來這樣的觀點:
在這裏我需要顯示陣列的所有文本。 這是我的代碼:
TableRow.LayoutParams lp = new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT , TableRow.LayoutParams.WRAP_CONTENT);
tablerow_product[i] = new TableRow(viewToLoad.getContext());
tablerow_product[i].setLayoutParams(lp);
product_spinner[i] = new Spinner(viewToLoad.getContext());
product_spinner[i].setLayoutParams(lp); product_spinner[i].setBackgroundResource(R.drawable.spinner_selector);
String[] proba={"red","blue"}; //first image is with this test array
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(viewToLoad.getContext(), com.Orange.R.layout.my_spinner_textview,spinnerArray); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
product_spinner[i].setAdapter(spinnerArrayAdapter);
tablerow_product[i].addView(product_spinner[i]); Themes_TableLayout.addView(tablerow_product[i],new TableLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
和my_spinner_textview.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/textorange_selected"
android:gravity="left"
android:singleLine="false"
android:ellipsize="end"/>
誰能幫助我解決這個問題?任何想法是受歡迎的。提前致謝。
一次檢查這個鏈接http://android-coding.blogspot.i n/2011/12/dynamic-change-content-of-spinner.html – shassss 2012-07-30 11:37:44
這個問題的答案解決了我的問題:http://stackoverflow.com/questions/2325242/android-how-do-i-add-1 -views-in-one-cell-for-tablerow – Gabrielle 2012-07-31 06:35:49
@Bhargavi我會很快用我的代碼發表一個答案。 – Gabrielle 2012-08-31 07:06:56