-2

I am working on a project with sqlite database but I can't seems to fix this problem. how can I fix it? Here is my code :

 TableRow.LayoutParams trs= new 
 TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 
 TableRow.LayoutParams.WRAP_CONTENT);
 trs.setMargins(0,0,0,0);

    for (int i = 0; i < id.length; i++)

    {

        /** Create a TableRow dynamically **/

        tr = new TableRow(this);

        tr.setLayoutParams(new TableRow.LayoutParams(

                TableRow.LayoutParams.FILL_PARENT,

                TableRow.LayoutParams.WRAP_CONTENT));

        /** Creating a TextView to add to the row **/

        idtxt = new TextView(this);
        AutofitHelper.create(idtxt);
        idtxt.setBackgroundColor(Color.parseColor("#00ff00"));
        idtxt.setText(id[i]);
        idtxt.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if(idtxt.getLineCount() > 1){
                    idtxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
                }
            }
        });


        idtxt.setTextColor(Color.RED);
        idtxt.setWidth(-100);
        idtxt.setTypeface(Typeface.DEFAULT, Typeface.BOLD);

        idtxt.setLayoutParams(trs);
      //  idtxt.setPadding(0, 0, 0, 5);
        idtxt.setBackgroundColor(new Color(Color.green()));

        tr.addView(idtxt);  // Adding textView to tablerow.
        tl.addView(tr, new TableLayout.LayoutParams(

                TableRow.LayoutParams.MATCH_PARENT,

                TableRow.LayoutParams.WRAP_CONTENT));
        // Add the TableRow to the TableLayout

        /** Creating a TextView to add to the row **/

        timestamptxt = new TextView(this);

        timestamptxt.setText(Timestamp[i]);

        timestamptxt.setTextColor(Color.RED);

        timestamptxt.setTypeface(Typeface.DEFAULT, Typeface.BOLD);

        timestamptxt.setLayoutParams(trs);
        timestamptxt.setPadding(-5, -5, -5, -5);
        tr.addView(timestamptxt);
        tl.removeView(tr);
        tl.addView(tr, new TableLayout.LayoutParams(

                TableRow.LayoutParams.MATCH_PARENT,

                TableRow.LayoutParams.WRAP_CONTENT));
        /** Creating a TextView to add to the row **/

        cosplaytxt = new TextView(this);

        cosplaytxt.setText(Cosplay_Name[i]);

        cosplaytxt.setTextColor(Color.RED);

        cosplaytxt.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        cosplaytxt.setLayoutParams(trs);

        cosplaytxt.setPadding(5, 5, 5, 5);
        tr.addView(cosplaytxt);
        tl.removeView(tr);
        tl.addView(tr, trs);

Here is the error

Abdul Kawee
  • 2,687
  • 1
  • 14
  • 26
  • What is your actual problem with the **TextView**? They appear to be spanning the whole screen width-wise. If you need to scroll down, although it feels like that is not what you are asking, you can simply wrap everything in a **ScrollView** – ViaTech Sep 07 '18 at 08:00
  • I just want to decrease the size of the textview for not spanning the whole screen , I added scrollview into it and when scroll the other datas can be seen correctly , just this text view is bigger and I want to fix it. – Keinpyi Si Sep 07 '18 at 08:06
  • Already tried your Solution before I post it in here . still the same error..... – Keinpyi Si Sep 07 '18 at 08:22
  • Ah okay this is pretty simple and I'm sure someone will provide an answer before I can as I will not be in a position to provide a real answer for a bit due to travel, but if you want to decrease the size of the **TextView**, try setting it to a static size like 400dp...or do it programmatically inside your activity and reduce the gathered dimensions by a set amount **(i.e -50 pixels)**... Look at this solution for an example of how to gather the user's runtime screen size: https://stackoverflow.com/a/4744499/8382028 – ViaTech Sep 07 '18 at 08:23
  • I will just have to wait then .... – Keinpyi Si Sep 07 '18 at 08:24

1 Answers1

0

Please set the height and width of of the textview to wrap_content. Currently the textview's width is match_parent. Try this.

tr.setLayoutParams(new TableRow.LayoutParams(
    TableRow.LayoutParams.WRAP_CONTENT,
    TableRow.LayoutParams.WRAP_CONTENT));
Sadda Hussain
  • 343
  • 5
  • 19