Edit text created in Grid Layout any Text typed not visible properly

0

A sample code where i need to have a Edit Text in a Grid Layout Problematically .But when the text are entered ,Only the small bottom portion of text is visible .The text is larger than expected. I need the edit text with text as shown in image which is Edit Text green background with only one line edit text required.Thanks

package com.example.myapplicationtesting;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.GridLayout;

public class MainActivity extends AppCompatActivity
{

    @SuppressLint("ResourceType")
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //LinearLayout linearLayout = findViewById(R.id.GroupContainer);
        GridLayout Glyout;// = findViewById(R.id.Glayout_item);
        Glyout = (GridLayout)findViewById(R.id.id_grid) ;

        Glyout.setColumnCount(4);
        Glyout.setRowCount(20);
        int rowIndex = 0 ;



        // Create EditText
        for(int i = 0 ; i< 10 ; i++)
        {
            rowIndex     = i ;
            EditText editText = new EditText(this);
            GridLayout.LayoutParams param = new GridLayout.LayoutParams();
            param.height = 50;//ViewGroup.LayoutParams.WRAP_CONTENT;
            param.width = 250 ;// GridLayout.LayoutParams.MATCH_PARENT;
            param.rowSpec = GridLayout.spec(rowIndex);
            param.columnSpec = GridLayout.spec(0);

            param.setMargins(0,5,0,0);

            editText.setTextColor(R.color.colorPrimaryDark);
            editText.setTextSize(10);
            editText.setBackgroundColor(0xFFFFFFFF);
            editText.setLayoutParams(param);
            if (rowIndex == 1) {
                editText.setId( R.id.task1);
            }
            if (rowIndex == 2) {
               editText.setId(R.id.task2);
            }

            //editText.setHeight(30);
           // editText.setWidth(180);
           // editText.setBackgroundColor(R.color.colorAccent);
            Glyout.addView(editText);
            rowIndex++;
        }



   }


}
android
android-edittext
asked on Stack Overflow May 13, 2020 by Naveen AIPL

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0