I am writing XML in following way, list_item2 contains TextView and EditText, while list_item is another XML contains only TextView,
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/textItem"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</EditText>
I am using the xml in ListView, such as
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if(position!=2) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.list_item, parent, false);
}
else {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.list_item2, parent, false);
}
TextView tv = (TextView) row.findViewById(R.id.textItem);
tv.setText(getItem(position));
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
but It is creating output like
TextView
EditText
I want both on same row, such as
TextView EditText
Any one edit the XML and let me know the hierarchy for creating GUI in Android Apps
Take your EditText
and TextView
inside a LinearLayout
having horizontal orientation (which is applied by default) and set layout_weight = 1
or whatever do you want to EditText
and TextView
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="@+id/textItem"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="10dp"
android:textSize="16sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/ >
</LinearLayout>
use following layout
<?xml version="1.0" encoding="utf-8"?
<LinearLayout
android:id="@+id/lnrTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:id="@+id/textItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weight="1"
android:textSize="16sp" >
</TextView>
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:weight="1"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With