Question

I am trying to put a RadioButtton in a GridView. I wanted to navigate to another Activity on clicking the radio button. but that's not happening.

could you please help me with the same. I need to add the code of RadioButtton in the following code:

package login.pkg;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;
public class Admin_view_users extends BaseAdapter 
{
    public OnClickListener monClick;
    Context mContext;
    private String [] id = {“S001″,”S002″,”S003″,”S004″};
    private String [] name={“Ameya”,”Anukta”,”Ankita”,”Ashish”};
    String[] meter_no = new String[]{“M10001″,”M10012″,”M10002″,”M10123″,”M10003″,”M10004″};
    private String[] acc_type= {“user”,”user”,”user”,”user”};
    private LayoutInflater mInflater;
    public Admin_view_users(Context c)
    {
         mContext=c;
         mInflater = LayoutInflater.from(c);
    }
    public void setOnClickListener(OnClickListener listener) {
        monClick = listener;
    // RadioButton rad = new RadioButton(newAdmin2);

    }
    public int getCount()
    {
         return id.length;
    }
    public Object getItem(int position)
    {
       return position;
    }
    public long getItemId(int position)
    {
         return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder=null;
        if(convertView==null)
        {
             convertView = mInflater.inflate(R.layout.customgrid,
                       parent,false);
             holder = new ViewHolder();
             holder.txtId=(TextView)convertView.findViewById(R.id.txtId);
             holder.txtId.setPadding(15, 10,10 , 10);
             holder.txtName=(TextView)convertView.findViewById(R.id.txtName);
             holder.txtName.setPadding(15, 10, 20, 10);
             holder.acc_type=(TextView)convertView.findViewById(R.id.txtEmail);
             holder.acc_type.setPadding(15, 10, 40, 10);

            //holder.rad = (RadioButton)convertView.findViewById(R.id.radioButton1);
            if(position==0)
            {
                convertView.setTag(holder);
             }
        }
        else
        {
           holder = (ViewHolder) convertView.getTag();
        }

        holder.txtId.setText(id[position]);
        holder.txtName.setText(name[position]);
        holder.acc_type.setText(acc_type[position]);

        // RadioButton rb= new RadioButton(newAdmin2);
        return convertView;
    }
     static class ViewHolder
     {
         TextView txtId;
         TextView txtName;
         TextView acc_type;
         RadioButton rad;
     }

}

Suggest me the way to do it..

Was it helpful?

Solution

Do not use RadioButton as it will confuse your users - RadioButtons are for selecting one of many options. Better try Button or ImageButton.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top