Subburaj
Subburaj

Reputation: 5192

Listview with Textview and 2 Edittext in a single row in android

I want to have a single "Textview" and 2 "Edittext" in a single row.I have tried the following code:

Xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"

   >


    <TextView 
        android:id="@+id/vegtext"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"        
       />

    <EditText 
        android:id="@+id/vegquantity"   
        android:hint="Qty"    
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_weight="1"
        />

     <EditText 
        android:id="@+id/vegprice"       
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:hint="price"
        android:layout_weight="1"
       />


</LinearLayout>

Getview in adapter:

@Override
    public View getView(int position, View convertview, ViewGroup parent) 
    {
         VeglistHolder holder;
        // TODO Auto-generated method stub
        if(convertview == null)
        {
            LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertview  = inflater.inflate(R.layout.veglistrow, null); 

             holder = new VeglistHolder();

             holder.text = (TextView) convertview
                        .findViewById(R.id.vegtext);


             holder.Qtyedit = (EditText) convertview
                        .findViewById(R.id.vegquantity);

             holder.priceedit = (EditText) convertview
                        .findViewById(R.id.vegprice);


             convertview.setTag(holder);            

        }
        else
        {
            holder = (VeglistHolder) convertview.getTag();      
        }



         holder.text.setText(vegitems[position]);
        return convertview;
    }

But the Edittext is not there in the row. Also some blank space is coming below the "TExtview" .I searched for "Lots of" post regarding this but i cant solve this.Please help me to solve this..Thanks in advance.

Upvotes: 0

Views: 840

Answers (3)

Raghunandan
Raghunandan

Reputation: 133560

Use a Realative layout. Modify the attributes to suit your requirement

<?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/textView1"
    android:layout_width="60dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="58dp"
    android:text="TextView" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="60dp" //set to whatever you desire
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView1"
    android:layout_alignBottom="@+id/textView1"
    android:layout_marginLeft="30dp"
    android:layout_toRightOf="@+id/textView1"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/editText2"
    android:layout_width="60dp"// //set to whatever you desire
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:layout_marginRight="70dp"
    android:ems="10"
    android:inputType="textPersonName" />

</RelativeLayout>

Upvotes: 1

M090009
M090009

Reputation: 1139

Well your problem is that you set the width and the height of the TextView to fill parent

Upvotes: 0

Rishabh Bhardwaj
Rishabh Bhardwaj

Reputation: 831

Try to use weightSum in main layout for equal partition as below

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="3"
android:orientation="vertical" >

Upvotes: 1

Related Questions