0

Im trying to add rows to a custom list view with user input, but I dont understand how to in the customadapter class..

The custom list view layout:

<TextView
    android:id="@+id/activityName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="28dp"
    android:layout_marginTop="22dp"
    android:textSize="35sp"
    android:text="Activity Name" />

<TextView
    android:id="@+id/xText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="19dp"
    android:text="x:"
    android:textSize="20sp"
    android:layout_below="@+id/activityName"
    android:layout_alignStart="@+id/activityName" />

<TextView
    android:id="@+id/yText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="y:"
    android:textSize="20sp"
    android:layout_alignBaseline="@+id/xText"
    android:layout_alignBottom="@+id/xText"
    android:layout_toEndOf="@+id/xText"
    android:layout_marginStart="32dp" />

<TextView
    android:id="@+id/zText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="z:"
    android:textSize="20sp"
    android:layout_marginEnd="119dp"
    android:layout_alignBaseline="@+id/yText"
    android:layout_alignBottom="@+id/yText"
    android:layout_alignParentEnd="true" />

I've managed to find some guides that show how to enter to a custom list view from arrays, but here I want it to be added from users input..

class CustomAdapter extends BaseAdapter{
    @Override
    public int getCount(){
        return 0;
    }
    @Override
    public Object getItem(int i)
    {
        return null;
    }
    @Override
    public long getItemId(int i)
    {
        return 0;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup)
    {
        view = getLayoutInflater().inflate(R.layout.customlistview, null);
        TextView activity_name = (TextView) view.findViewById(R.id.activityName);
        TextView x_text = (TextView) view.findViewById(R.id.xText);
        TextView y_text = (TextView) view.findViewById(R.id.yText);
        TextView z_text = (TextView) view.findViewById(R.id.zText);

    return view;
    }

}

Could someone help please?

1

1 Answer 1

0

To dynamically change a list or add or delete any list item, you should use an ArrayList.

Where is your ArrayList or Array where the listItems are stored? Please add every details.

You should use RecyclerView instead of ListView. It is more configurable and dynamic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.