Reputation: 999
I have a custom listview and want to put edittext inside it, I put it on the right but when I run, it went to left, like this:
on my graphical layout:
on my emulator:
it suppose to be on the right, this is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txtListVDokterRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/edtListVDokterType"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterRuper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/edtListVDokterType"
android:layout_marginLeft="100dp"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterKelas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/edtListVDokterType"
android:layout_marginLeft="190dp"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterRuang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/edtListVDokterType"
android:layout_marginLeft="280dp"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterNama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/edtListVDokterType"
android:layout_marginLeft="370dp"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="660dp"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone" />
<TextView
android:id="@+id/txtListVDokterVST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="750dp"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone" />
<CheckBox
android:id="@+id/cekListVDokterVst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<EditText
android:id="@+id/edtListVDokterType"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/cekListVDokterVst"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
I tried clean it but it didn't work
Upvotes: 0
Views: 56
Reputation: 11988
First, set the CheckBox
which aligns to parent's right. Then with its id, make your EditText
to its left:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/cekListVDokterVst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<EditText
android:id="@+id/edtListVDokterType"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/cekListVDokterVst"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
In a RelativeLayout
, when you play with ids, you must declare firstly the views and its ids and then according to it, declare the attributes like toLeftOf, above, below, etc, on other views.
EDIT:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- set the checkbox and your edittext to the first position -->
<CheckBox
android:id="@+id/cekListVDokterVst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<EditText
android:id="@+id/edtListVDokterType"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/cekListVDokterVst"
android:ems="10" >
<requestFocus />
</EditText>
<!-- set the other views according to the first ids above -->
<TextView
android:id="@+id/txtListVDokterRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@id/edtListVDokterType"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<!-- as I can see on your layout, you create the other views with
margin attributes, maybe you should create with toRightOf attribute.
>>> instead of margin=100dp/190dp... >>> use the following -->
<TextView
android:id="@+id/txtListVDokterRuper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@id/edtListVDokterType"
android:layout_toRightOf="@id/txtListVDokterRegister"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterKelas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@id/edtListVDokterType"
android:layout_toRightOf="@id/txtListVDokterRuper"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtListVDokterRuang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@id/edtListVDokterType"
android:layout_toRightOf="@id/txtListVDokterKelas"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge" />
<!-- ... -->
</RelativeLayout>
Last note: when you set a new id, you do @+id/...
but when you need to use an id, do @id/...
(without the +
). You don't need to "recreate" an id.
Hope this helps.
Upvotes: 1