Sunday, 10 March 2013

Android ListView with RadionGroup and TextView

In previous blog  i shown you ListView with RadioGroup, CheckBox.
Now i will use RadioGroup with TextView.
























Download full source code Click ListWithRadioGroupandTextView

Please leave your feedback to amithigh.gupta@gmail.com

So please fell free to ask any doubt, any query will be highly appreciated.
Thanks,

Thursday, 7 March 2013

Android Custon Single choice LsitView with Custom RadioButton



In Previous blog i posted Some ListView example related to TextView with Image, Slide Animation.
Now in this post i will use custom RadioButton i.e Single Choice ListView.


























Download Full Source code Click CustomSingleChoiceList

Later i will update full documentation on this.

Hope this post will really help you.
Please post your comment and ask any question.
I will be always for quick reply..
Thanks

Wednesday, 6 March 2013

Android Alert Dialog With Single choice list(Like Spinner)

We can use AlertDialog with not only "Yes" or "No" but also can represent like Spinner.

Screenshots:-























Screenshots:- After clicking Button a Alert Dialog will appear with Single choice list.























Screenshots:- Alert Dialog with single choice list and EditText
























Download Full Source code click AlertDialogLikeSpinner


Android ListView with Animation.

ListView is a very useful widget. Through animation we can show a ListView as ExpandibleListView.

Screenshots:- When you will click any list item item i view will open like sliding. if you click other list item then it will close the previous one and open the current item.
So it will behave like ExpandibleList.


Download Full source code click ListViewWithAnimation























Screenshots:2)























Steps are as follows:-

Step1) ExpandListItem.java


package com.list.animation;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout.LayoutParams;

public class ExpandListItem extends Animation {
    private View mAnimatedView;
    private LayoutParams mViewLayoutParams;
    private int mMarginStart, mMarginEnd;
    private boolean mIsVisibleAfter = false;
    private boolean mWasEndedAlready = false;

    /**
     * Initialize the animation
     * @param view The layout we want to animate
     * @param duration The duration of the animation, in ms
     */
    public ExpandListItem(View view, int duration) {

        setDuration(duration);
        mAnimatedView = view;
        mViewLayoutParams = (LayoutParams) view.getLayoutParams();

        // decide to show or hide the view
        mIsVisibleAfter = (view.getVisibility() == View.VISIBLE);

        mMarginStart = mViewLayoutParams.bottomMargin;
        mMarginEnd = (mMarginStart == 0 ? (0- view.getHeight()) : 0);

        view.setVisibility(View.VISIBLE);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);

        if (interpolatedTime < 1.0f) {

            // Calculating the new bottom margin, and setting it
            mViewLayoutParams.bottomMargin = mMarginStart
                    + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

            // Invalidating the layout, making us seeing the changes we made
            mAnimatedView.requestLayout();

        // Making sure we didn't run the ending before (it happens!)
        } else if (!mWasEndedAlready) {
            mViewLayoutParams.bottomMargin = mMarginEnd;
            mAnimatedView.requestLayout();

            if (mIsVisibleAfter) {
                mAnimatedView.setVisibility(View.GONE);
            }
            mWasEndedAlready = true;
        }
    }
}


Step2) MainActivity .java

package com.list.animation;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener{

private List<String> data;
    ListAdapter adapter;
    int selected = -1;
    boolean firsttime = false;
    View bottomview1 = null, bottomview2 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        data = new ArrayList<String>();
        fillData();
        adapter = new ListAdapter(this, data);
        ListView lvMain = (ListView) findViewById(R.id.list);
        lvMain.setAdapter(adapter);
        lvMain.setOnItemClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    void fillData() {
        for (int i = 1; i <= 5; i++) {
            data.add("Heading" + i);
        }
    }

@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
if (position == selected) {
if (firsttime) {
ExpandListItem expandAnim = new ExpandListItem(
bottomview2, 1000);
bottomview2.startAnimation(expandAnim);
} else {
ExpandListItem expandAni = new ExpandListItem(
bottomview1, 1000);
bottomview1.startAnimation(expandAni);
}
selected = -1;

} else if (selected >= 0) {

ExpandListItem expandAni = new ExpandListItem(bottomview1,
1000);
bottomview1.startAnimation(expandAni);
bottomview2 = view.findViewById(R.id.hidden);
ExpandListItem expandAnim = new ExpandListItem(bottomview2,
1000);
bottomview2.startAnimation(expandAnim);
selected = position;
bottomview1 = bottomview2;
firsttime = true;
}else
{
bottomview1 = view.findViewById(R.id.hidden);
ExpandListItem expandAni = new ExpandListItem(bottomview1,
1000);
bottomview1.startAnimation(expandAni);
selected = position;
}
}

}

Step3) layout/main.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="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

Step4) list_item.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="vertical" >

    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:padding="20dip" />

    <LinearLayout
        android:id="@+id/hidden"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_marginBottom="-50dip"
        android:visibility="gone" >

        <Button
            android:id="@+id/doSomething1"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:focusable="false"
            android:layout_marginLeft="50dp"
            android:focusableInTouchMode="false"
            android:text="@string/menu_item1" />

        <Button
            android:id="@+id/doSomething2"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="@string/menu_item2" />

    </LinearLayout>

</LinearLayout>


Step5) ListAdapter .java


package com.list.animation;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter {
Context ctx;
    LayoutInflater lInflater;
    List<String> data;

    ListAdapter(Context context, List<String> data) {
        ctx = context;
        this.data = data;
        lInflater = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = lInflater.inflate(R.layout.list_item, parent, false);
        }
        ((TextView) view.findViewById(R.id.title)).setText(data.get(position));
       
        return view;
    }
}

Thanks,
feel free to ask any thing and post your comments.


Android ListView with Alternate list item background and hover.

Now i will show how to make a ListView with Alternate color i.e for odd position having different background and for even position of  List item having different background as well as different hover color.

Screenshots:-
























These are the following steps to do show.

Step1.1) Use two selector for odd and even postion list item

artists_list_backgroundcolor.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
 android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@color/grey" />
<item android:state_pressed="true"
    android:drawable="@color/itemselected" />
<item android:state_selected="true"
 android:state_pressed="false"
    android:drawable="@color/itemselected" />
</selector>


Step 1.2)
artists_list_background_alternate.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
 android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@color/sign_out_color" />
<item android:state_pressed="true"
    android:drawable="@color/login_hover" />
<item android:state_selected="true"
 android:state_pressed="false"
    android:drawable="@color/login_hover" />
</selector>

Step2)
colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <color name="survey_toplist_item">#EFEDEC</color>
    <color name="survey_alternate_color">#EBE7E6</color>
    <color name="grey">#ffffff</color>
    <color name="itemselected">#EDEDED</color>
    <color name="login_hover">#E5F5FA</color>
    <color name="sign_out_color">#e84040</color>

</resources>

Step 3.1)
activity_main.xml

<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"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp" />

</RelativeLayout>

Step3.2) res/layout/listitem,xml

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

    <TextView
        android:id="@+id/heading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:padding="15dp" />

</LinearLayout>

Step4)
MainActivity.java

package com.amit.listalternate;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;

public class MainActivity extends Activity {
    private List<String> data;
    ListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        data = new ArrayList<String>();
        fillData();
        adapter = new ListAdapter(this, data);
        ListView lvMain = (ListView) findViewById(R.id.list);
        lvMain.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    void fillData() {
        for (int i = 1; i <= 20; i++) {
            data.add("Heading" + i);
        }
    }

}

Step 5) Adapter
ListAdapter.java



package com.amit.listalternate;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter{
    Context ctx;
    LayoutInflater lInflater;
    List<String> data;

    ListAdapter(Context context, List<String> data) {
        ctx = context;
        this.data = data;
        lInflater = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = lInflater.inflate(R.layout.listitem, parent, false);
        }

        if (position % 2 == 0) {
            view.setBackgroundResource(R.drawable.artists_list_backgroundcolor);
        } else {
            view.setBackgroundResource(R.drawable.artists_list_background_alternate);
        }

        ((TextView) view.findViewById(R.id.heading)).setText(data.get(position));
       
        return view;
    }
}

Download full source code click ListViewWithAlternateColor









Tuesday, 5 March 2013

Android Listview with CheckBox and a button to get the selected option.

A Listview may be single choice or Multiple Choice.

Now i am going to show you a list of Item with Checkbox, once you will select your answer by checking the checkbox and click the bottom Button it will display all the selected answer as well as Total Amount.


Screenshots:- 1) This is first screen once you run the application
























Screenshots-2) Select your answer here.
























Screenshots:3) Final 

























Now in order to achieve plz follow foloowing steps:-

Step1) res/layout/activity_main.xml

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

    <ListView
        android:id="@+id/lvMain"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </ListView>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="5dp"
        android:onClick="showResult"
        android:text="@string/get_answer" >
    </Button>

</LinearLayout>

Step2) res/layout/item.xml

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

    <CheckBox
        android:id="@+id/cbBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" >
    </CheckBox>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:orientation="vertical"
        android:layout_weight="1" >

        <TextView
            android:id="@+id/tvDescr"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text=""
            android:textSize="20sp" >
        </TextView>

        <TextView
            android:id="@+id/tvPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="" >
        </TextView>
    </LinearLayout>

    <ImageView
        android:id="@+id/ivImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_gravity="right"
        android:contentDescription="@string/app_name" >
    </ImageView>

</LinearLayout>

Step3) src/Product.java

package com.amit.listview;

public class Product {
    String name;
      int price;
      int image;
      boolean box;
     

      Product(String _describe, int _price, int _image, boolean _box) {
        name = _describe;
        price = _price;
        image = _image;
        box = _box;
      }
    }
Step4) src/ListAdapter.java

package com.amit.listview;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter {
    Context ctx;
    LayoutInflater lInflater;
    ArrayList<Product> objects;

    ListAdapter(Context context, ArrayList<Product> products) {
        ctx = context;
        objects = products;
        lInflater = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public Object getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = lInflater.inflate(R.layout.item, parent, false);
        }

        Product p = getProduct(position);

        ((TextView) view.findViewById(R.id.tvDescr)).setText(p.name);
        ((TextView) view.findViewById(R.id.tvPrice)).setText(p.price + "");
        ((ImageView) view.findViewById(R.id.ivImage)).setImageResource(p.image);

        CheckBox cbBuy = (CheckBox) view.findViewById(R.id.cbBox);
        cbBuy.setOnCheckedChangeListener(myCheckChangList);
        cbBuy.setTag(position);
        cbBuy.setChecked(p.box);
        return view;
    }

    Product getProduct(int position) {
        return ((Product) getItem(position));
    }

    ArrayList<Product> getBox() {
        ArrayList<Product> box = new ArrayList<Product>();
        for (Product p : objects) {
            if (p.box)
                box.add(p);
        }
        return box;
    }

    OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            getProduct((Integer) buttonView.getTag()).box = isChecked;
        }
    };
}


Step 5) Your MainActivty.java

package com.amit.listview;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

    ArrayList<Product> products = new ArrayList<Product>();
    ListAdapter boxAdapter;

      /** Called when the activity is first created. */
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fillData();
        boxAdapter = new ListAdapter(this, products);

        ListView lvMain = (ListView) findViewById(R.id.lvMain);
        lvMain.setAdapter(boxAdapter);
      }

      void fillData() {
        for (int i = 1; i <= 20; i++) {
          products.add(new Product("Product " + i, i * 100,
              R.drawable.ic_launcher, false));
        }
      }

      public void showResult(View v) {
        String result = "Selected Product are :";
        int totalAmount=0;
        for (Product p : boxAdapter.getBox()) {
          if (p.box){
            result += "\n" + p.name;
            totalAmount+=p.price;
          }
        }
        Toast.makeText(this, result+"\n"+"Total Amount:="+totalAmount, Toast.LENGTH_LONG).show();
      }
    }

Step6) res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">ListViewWithButton</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
     <string name="get_answer">Click to get Selected Answer</string>

</resources>

Download full source code click ListWithButton








Android ListView with Horizontal CheckBox.Part-2

Part-2
In previous blog i shown Listview with RadioGroup and RadioButton.
Now i am going to show how to make a list of Horizontal CheckBox.


Screenshot.1) Before selecting any Checkbox
























Screenshots.2) After Checked the list of Checkbox
























In Previous blog i used RadioGroup to achieve the ListView with horizontal RadioButton.
But for Checkbox i am going to use LinearLayout and inflate the view in Adapter class.


Steps:-

1) res/layout/activity_main.xml

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"
    tools:context=".MainActivity" >
    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp" />
</RelativeLayout>

2) res/layout/horizontal_checbox.xml

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

    <TextView
        android:id="@+id/headingitem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:padding="5dp" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearmain"
        android:layout_gravity="center_horizontal|center_vertical"
        android:orientation="horizontal" >
    </LinearLayout>

</LinearLayout>

3) src/ListAdapter.java

package com.list.checkbox;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class ListAdapter extends ArrayAdapter<Option> {

    Context context;
    int layoutResourceId;
    Option data[] = null;

    public ListAdapter(Context context, int layoutResourceId,
            Option[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        MatrixHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new MatrixHolder();
            holder.txtTitle = (TextView) row.findViewById(R.id.headingitem);
            holder.position = position;
            holder.layout = (LinearLayout) row.findViewById(R.id.linearmain);
            final CheckBox[] checkbox = new CheckBox[5];
           
            for (int i = 0; i < 5; i++) {
                checkbox[i] = new CheckBox(context);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        0, LayoutParams.WRAP_CONTENT);
                params.weight = 1f;
                params.setMargins(10, 0, 10, 10);
                holder.layout.addView(checkbox[i], params);
            }

            row.setTag(holder);
        } else {
            holder = (MatrixHolder) row.getTag();
        }

        Option option = data[position];
        holder.txtTitle.setText(option.title);
        return row;
    }

    static class MatrixHolder {
        TextView txtTitle;
        LinearLayout layout;
        int position;
    }
}

4) finally Your MainActivity.java

package com.list.checkbox;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;

public class MainActivity extends Activity {
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         Option weather_data[] = new Option[]
                    {
                        new Option("Heading1"),
                        new Option("Heading2"),
                        new Option("Heading3"),
                        new Option("Heading4"),
                        new Option("Heading5")
                    };
            ListAdapter adapter = new ListAdapter(this,
                            R.layout.horizontal_checbox, weather_data);
                    listView = (ListView)findViewById(R.id.list);
                    listView.setAdapter(adapter);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }


       
    }


Download full source code Click ListWithHorizontalCheckbox


Monday, 4 March 2013

Android ListView with RadioGroup and RadioButton.Part-1

Part-1

Till Now we have use ListView with the following widgets
1.TextView
2.ImageView
3.Button

Today i am going to use RadioGroup. 
Note *- It can be achieved by GridView but ListView is the optimal widget to use. 

Screen Shots:- List of RadioGroup with dynamically added RadioButton























Its very simple to show ListView like this.

Steps:-)

1)
res/layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp" />

</RelativeLayout>


Step2) listitem.xml

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

    <TextView
        android:id="@+id/heading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:padding="0dp" />

    <RadioGroup
        android:id="@+id/radio_group1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:orientation="horizontal" >
    </RadioGroup>

</LinearLayout>

Step3) Option.java
src/Option.java

package com.matrix.question;

public class MatrixOption {
        public String title;
        public MatrixOption(){
            super();
        }
       
        public MatrixOption( String title) {
            super();
            this.title = title;
        }
    }

Step 4) MainActivity.java

package com.list.radiogroup;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainActivity extends Activity {
     private ListView listView1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
       Option weather_data[] = new Option[]
                {
                    new Option (""),
                    new Option (""),
                    new Option (""),
                    new Option (""),
                    new Option ("")

                   /* new Option ("Heading1"),
                    new Option ("Heading2"),
                    new Option ("Heading3"),
                    new Option ("Heading4"),
                    new Option ("Heading5")*/
                };
        RadioGroupAdapter adapter = new RadioGroupAdapter (this,
                        R.layout.matrix, weather_data);
                listView1 = (ListView)findViewById(R.id.list);
                listView1.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
   
}

Step 5) Adapter
RadioGroupAdapter.java

package com.list.radiogroup;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class RadioGroupAdapter extends ArrayAdapter<MatrixOption> {

    Context context;
    int layoutResourceId;
   Option data[] = null;

    public RadioGroupAdapter(Context context, int layoutResourceId,
            MatrixOption[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        RadioHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new RadioHolder ();
            holder.txtTitle = (TextView) row.findViewById(R.id.heading);
            holder.group = (RadioGroup) row.findViewById(R.id.radio_group1);
            final RadioButton[] rb = new RadioButton[5];
            for(int i=0; i<5; i++){
                rb[i]  = new RadioButton(context);
//                rb[i].setButtonDrawable(R.drawable.single_radio_chice);
                rb[i].setId(i);
                RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
                        0, LayoutParams.WRAP_CONTENT);
                params.weight=1.0f;
                params.setMargins(15, 0, 5, 10);
                holder.group.addView(rb[i],params); //the RadioButtons are added to the radioGroup instead of the layout
            }
            row.setTag(holder);
        } else {
            holder = (MatrixHolder) row.getTag();
        }

        Option option = data[position];
        holder.txtTitle.setText(option.title);
        return row;
    }

    static class RadioHolder {
        TextView txtTitle;
        RadioGroup group;
        int position;
    }
}



Download full Source code Click ListWithRadioGroup

Feel free if any one have any doubt.