1Answer
  • 9
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Wrong TableLayout Weight

I'm using a table layout inside a linear layout and the first row turns out fine but the consecutive rows are entirely the wrong weight despite setting both of them. I'm not sure if this is an issue with the version of Android Studio I'm running or maybe it doesn't work with kotlin... is there any way to fix it? I've updated everything.

I know Table Layout is pretty dated but I seriously do not want to use Constraint Layout, I absolutely hate it. It's way too much work for what I'm making.

activity_main.xml

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" android:background="@android:color/background_light"
        android:orientation="vertical">
    <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" android:layout_weight="8" android:orientation="horizontal">

        <TableRow android:layout_width="match_parent" android:layout_height="match_parent">
            <TextView
                    android:text="@string/loan_amount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:id="@+id/textView15" android:textSize="18sp"
                    android:textStyle="bold" android:layout_weight="3"/>
            <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="numberDecimal"
                    android:ems="10"
                    android:id="@+id/loanAmount" android:layout_weight="7"/>
        </TableRow>
        <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <TextView
                    android:text="TextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:id="@+id/textView38" android:layout_weight="1"/>
            <TextView
                    android:text="TextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:id="@+id/textView39" android:layout_weight="1"/>
            <TextView
                    android:text="TextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:id="@+id/textView40" android:layout_weight="1"/>
        </TableRow>
    </TableLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

Just set your layout_width to 0dp in the TableRow items. If you want to center the content add android:gravity="center" to the TextViews.

Code without gravity would look like this:

<TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <TextView
                android:text="TextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content" android:id="@+id/textView38" android:layout_weight="1"/>
        <TextView
                android:text="TextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content" android:id="@+id/textView39" android:layout_weight="1"/>
        <TextView
                android:text="TextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content" android:id="@+id/textView40" android:layout_weight="1"/>
    </TableRow>
  • 1
Reply Report