0
In my application has a vertical linear layout with id:
@+id/items
In this layout for each item contained in a list, I would like to create another horizontal Linear Layout called, Row containing 2 Imagebutton and an Edittext, an Imagebutton when clicked would remove the current item, another would mark the item as correct.
XML da Activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.leonardo.quiz.QuestionFormActivity">
<ImageButton
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/btn_media"
android:layout_centerHorizontal="true"
android:contentDescription="@string/ipt_media"
android:src="@drawable/question" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ipt_value"
android:layout_below="@+id/btn_media"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/items"
android:layout_below="@+id/ipt_value"
android:layout_centerHorizontal="true"
></LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_add"
android:id="@+id/btn_add"
android:layout_centerHorizontal="true"
android:layout_below="@id/items"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btn_back"
android:id="@+id/btn_back"
android:layout_below="@id/btn_add"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btn_exit"
android:id="@+id/btn_exit"
android:layout_below="@id/btn_back"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btn_save"
android:id="@+id/btn_save"
android:layout_below="@+id/btn_exit"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
However, what is the correct way to fill this Linearlayout entirely in JAVA, remembering that it will have another Linearlayout containing Imagebutton and Edittext.
Will you have to create these elements based on a list? If yes, a
ListView
doesn’t meet your need? Otherwise, have a look at these responses: http://answall.com/questions/35636/como-addir-um-imageview-em-um-relativelayout-em-runtimer/35638#35638:http://answall.com/questions/32225/botão-para-addir-um-novo-campo/32244#32244 and http://en.stackoverflow.com/questions/35636/how-to-add-an-imageview-in-a-relativelayout-in-runtimer/35638#35638 and see if it doesn’t meet.– Wakim
Actually I prefer not to use a Listview, and the View items should increase with the number of items and should not be rolling
– user5020
Then you will have to make the addition programmatically. Take a look at these two questions/answers to see if it no longer answers your question.
– Wakim
I’m already able to create programmatically, but Imagebutton needs to have a specific size, how do I do it , using Layoutparams.
– user5020