0

Currently i am trying to add TableRow by clicking the Button. The TableLayout is located in every listView item, so every time i add new item the new TableRow is created with potencial TableRows. Visual result is satifying, but when i am trying to tap(click) on one of added EditText, it cannot be focused, only one is working as expected. Here are the key parts of code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:orientation="vertical"
    android:padding="5dp">

    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/nameRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.75"
            android:ellipsize="marquee"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:singleLine="true"
            android:text="Wycisnianie żołnierskie"
            android:textColor="#000000"
            android:textSize="20sp" />

        <Button
            android:id="@+id/deleteRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:background="@color/colorPrimary"
            android:ellipsize="marquee"
            android:text="DELETE"
            android:textColor="#000000"
            android:textSize="17sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layout1"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/numberRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:gravity="center"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="#"
            android:textColor="#000000"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/kgRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:gravity="center"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="(+Kg)"
            android:textColor="#000000"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/RepetitionRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:gravity="center"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Reps"
            android:textColor="#000000"
            android:textSize="20sp" />
    </LinearLayout>

    <TableLayout
        android:id="@+id/tableLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/layout2">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


        </TableRow>
    </TableLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tableLayout"
        android:orientation="horizontal">

        <Button
            android:id="@+id/addRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:ellipsize="marquee"
            android:text="Add set"
            android:focusableInTouchMode="false"
            android:textColor="#000000"
            android:textSize="17sp" />
    </LinearLayout>
</RelativeLayout>

Here is the xml of the main view with list:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.ukleja.gymprogress.CreateTrainingActivity">


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="15dp"
        android:src="@drawable/ic_check_black_24dp"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/descriptionTraining"
            android:layout_weight="0.65"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="description"
            android:inputType="textPersonName"
            ></EditText>

        <TextView
            android:id="@+id/dateText"
            android:layout_weight="0.35"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:text="@string/_25_06_2019"
            android:textAlignment="viewStart"
            android:textColor="#000000"
            android:textSize="20sp"
            android:maxLines="1"
            android:textStyle="bold"/>

    </LinearLayout>

        <ListView
            android:id="@+id/exerciseList"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:dividerHeight="7dp"
            android:scrollbars="vertical"
            tools:listitem="@layout/traning_row" />

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

and the row xml itself:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:orientation="vertical"
    android:padding="5dp">

    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/nameRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.75"
            android:ellipsize="marquee"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:singleLine="true"
            android:text="Wycisnianie żołnierskie"
            android:textColor="#000000"
            android:textSize="20sp" />

        <Button
            android:id="@+id/deleteRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:background="@color/colorPrimary"
            android:ellipsize="marquee"
            android:text="DELETE"
            android:textColor="#000000"
            android:textSize="17sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layout1"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/numberRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:gravity="center"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="#"
            android:textColor="#000000"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/kgRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:gravity="center"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="(+Kg)"
            android:textColor="#000000"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/RepetitionRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:gravity="center"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Reps"
            android:textColor="#000000"
            android:textSize="20sp" />
    </LinearLayout>

    <TableLayout
        android:id="@+id/tableLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/layout2">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


        </TableRow>
    </TableLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tableLayout"
        android:orientation="horizontal">

        <Button
            android:id="@+id/addRow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:ellipsize="marquee"
            android:text="Add set"
            android:focusableInTouchMode="false"
            android:textColor="#000000"
            android:textSize="17sp" />
    </LinearLayout>


</RelativeLayout>

Here is the gif that is showing the behavoiur( only link because i cannot post images)

https://i.stack.imgur.com/kJNCF.gif

EDIT:

The main problem is starting to appear, when I am trying to add InputType to EditText, without it, the EditText's are working almost as they should be( need two taps currently). So the bad things happen when i am adding this line to code:

 tv2.inputType = InputType.TYPE_CLASS_NUMBER
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Ukleja
  • 3
  • 4
  • Possible duplicate of [Focusable EditText inside ListView](https://stackoverflow.com/questions/2679948/focusable-edittext-inside-listview) – KuLdip PaTel Aug 16 '19 at 13:03
  • Unfortunatelly there was no propper answear that could help, tried everything from there. – Ukleja Aug 17 '19 at 19:16

0 Answers0