Forum Xamarin Xamarin.Android

Please critque my code

james432213james432213 Member ✭✭
edited December 2019 in Xamarin.Android

Hi, I'm relatively new to Xamarin and android so if you may, please critique how I've dynamically populated the interface.
Thank you

            //Root
            LinearLayout LLRows = FindViewById<LinearLayout>(Resource.Id.rowsLinearLayout);

            //Parameters
            var paramImageView = new RelativeLayout.LayoutParams(150, 150);
            paramImageView.SetMargins(0, 0, 0, 0); 

            var paramEditTextName = new RelativeLayout.LayoutParams(729, 120);
            paramEditTextName.SetMargins(0,0,0,-55); //bring the bottom margin up


            var paramTextViewCategory = new RelativeLayout.LayoutParams(150, 80);
            paramTextViewCategory.SetMargins(0, 0, 0, -40); //bring the bottom margin up

            var paramEditTextPrice = new RelativeLayout.LayoutParams(150, 160);
            paramEditTextPrice.SetMargins(0, 0, 0, -160); //bring the bottom margin up

            //Create image view
            var iV = new ImageView(this);
            //Get resource id
            var mydrw = (int)typeof(Resource.Drawable).GetField("defaultCase").GetValue(null);
            //Set the image resource as the resource id
            iV.SetImageResource(mydrw);


            //Edit text - name
            var etName = new EditText(this);
            //Set the text as the component's object name
            etName.SetText(pullComponent.Name, TextView.BufferType.Editable);
            //Set x, y position
            etName.TranslationX = 150;
            etName.TranslationY = -100;

            //Create text view
            var tVCategoryName = new TextView(this);
            tVCategoryName.Text = pullComponent.CategoryName;
            tVCategoryName.SetTypeface(null, Android.Graphics.TypefaceStyle.Bold);
            //Set x, y position
            tVCategoryName.TranslationX = 35;
            tVCategoryName.TranslationY = -65;

            //Edit text - price
            var etPrice = new EditText(this);
            //Set the text as the component's object price
            etPrice.SetText("$" + pullComponent.Price, TextView.BufferType.Editable);
            //Set x, y position
            etPrice.TranslationX = 880;
            etPrice.TranslationY = -245;

            //Add compontents
            LLRows.AddView(iV, paramImageView);
            LLRows.AddView(etName, paramEditTextName);
            LLRows.AddView(tVCategoryName, paramTextViewCategory);
            LLRows.AddView(etPrice, paramEditTextPrice); 

<TextView
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/txtViewAddComponent"
    android:text="Add component"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="5dp" />

<ScrollView
android:minWidth="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView1">
    <LinearLayout
        android:id="@+id/rowsLinearLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RelativeLayout
            android:orientation="horizontal"
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/relativeLayoutDefaultCase">
            <ImageView
                android:layout_width="55.5dp"
                android:layout_height="54.0dp"
                android:id="@+id/imgViewDefaultCase"
                android:src="@drawable/defaultcase"/>
            <TextView
                android:text="Case"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_width="wrap_content"
                android:layout_height="35.0dp"
                android:id="@+id/txtViewCaseLabel"
                android:textStyle="bold"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="55dp"/>
            <android.support.design.widget.TextInputEditText
                android:layout_height="42.5dp"
                android:id="@+id/txtEditCase"
                android:layout_width="273.5dp"
                android:layout_marginLeft="60dp"
                android:layout_marginTop="20dp" />
            <android.support.design.widget.TextInputEditText
                android:layout_width="wrap_content"
                android:layout_height="42.5dp"
                android:id="@+id/txtEditCasePrice"
                android:text="$0"
                android:layout_marginLeft="330dp"
                android:layout_marginTop="20dp" />
        </RelativeLayout>
    </LinearLayout>

</ScrollView>

The data is just for testing

Sign In or Register to comment.