我試圖將RadioButtton
放在GridView
中。我想單擊單選按鈕導航到另一個Activity
。但這並沒有發生。如何打開GridView中單擊RadioButton的活動
你能否幫我一樣。我需要在下面的代碼添加RadioButtton
代碼:
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;
}
}
建議我做的方式..
其中你在你的代碼中使用網格視圖 – user1203673 2012-02-29 07:41:06
爲什麼不把RadioButton放在RadioGroup中,而是添加onChangeListener呢? – Demonick 2012-02-29 08:25:11