Frage

i have a problem with my application. Basically what it does, is when i click a button, it creates 3 fields (2 editText and 1 spinner) on a scrollView. The thing works well, the only problem that im having, is related with the style, the activity bgColor is white(as the rest of the app) but, when i create elements programmatically, these elements doesnt have the look of the rest of my app. The editTexts are white with white letters (impossible to read since my bgColor is white as well) and its the same thing with the spinner. What can i do? Here is a snipet of code so you can see what im doing here.

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;

I know my XML is working well because if i create the 3 views on my xml, they look great. PD: Thx in advance for any help! Greetings.

War es hilfreich?

Lösung 3

I had a error in my code. When creating the fields, i was using (getApplicationContext());. I fixed it using MyApplicationName.this.

Andere Tipps

you can use

amount.setTextColor(Color.BLACK);

to set colour of text to black or any other colour
same can be used for spinner

Here's how I set the colors of my edit text lines and other theme-related android views.

http://android-holo-colors.com/

I just picked the color and views I wanted, then unzipped them in my res folder, then set the theme according the android tutorials.

I recommend backing up your res folder first, in case you don't like the results.

Garret

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top