アプリケーションに問題があります。基本的には、ボタンをクリックすると、scrollView に 3 つのフィールド (2 つの editText と 1 つのスピナー) が作成されます。うまく機能します。私が抱えている唯一の問題はスタイルに関連しています。アクティビティbgColorは(アプリの残りの部分と同様に)白ですが、プログラムで要素を作成すると、これらの要素は私の残りの部分の外観を持っていませんアプリ。editTexts は白い文字で白く (私の bgColor も白なので読むことができません)、スピナーと同じです。私に何ができる?ここにコードのスニペットがあるので、ここで何をしているのかを見ることができます。
public class AddIngredients extends Activity {
public int Count = 0;
public String[] spinnerArray = {"Gr", "kg", "Cups", "ml", "L", "oz"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addingredients);
final TableLayout lm = (TableLayout) findViewById(R.id.TableMain);
TableLayout.LayoutParams params = new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button addMore = (Button)findViewById(R.id.addmore);
addMore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TableRow ll = new TableRow(getApplicationContext());
//ll.setOrientation(LinearLayout.HORIZONTAL);
EditText product = new EditText(getApplicationContext());
product.setHint(" Ingredient "+Count +" ");
// Create Button
EditText amount = new EditText(getApplicationContext());
// Give button an ID
amount.setId(Count);
amount.setHint("Quantity");
final Button btn2 = new Button(getApplicationContext());
btn2.setId(Count);
btn2.setText("Remove " + Count);
Spinner spinner = new Spinner(getApplicationContext());
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
spinner.setAdapter(spinnerArrayAdapter);
ll.addView(product);
ll.addView(amount);
ll.addView(spinner);
lm.addView(ll);
Count = Count + 1;
XML で 3 つのビューを作成すると見栄えがよくなるので、XML がうまく機能していることはわかっています。PD: 助けが必要な場合は事前に Thx! ご挨拶。