大家好我正在创建一个自定义列表视图,其中包含textview和radiobuttons,必须以编程方式定义,因为我必须从数组中取出它,并且根据数组我必须创建它。到目前为止,我能够创建自定义列表视图textview但我不知道如何使用单选按钮创建无线电组并添加查看任何帮助你们将非常感谢这是我的代码下面
public abstract class LearnActivity extends ListActivity implements RadioGroup.OnCheckedChangeListener {
String tag = "Events";
private ProgressDialog m_ProgressDialog = null;
private ArrayList<mac> m_orders = null;
private OrderAdapter m_adapter;
private Runnable viewOrders;
String[] values = new String[] { "Android", "iPhone", "Windows",
"Black", "WebOS", "Ubuntu", "Windows7", "MaxOSX",
"Linux", "OS/2" };
int index = values.length;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(tag," event7");
m_orders = new ArrayList<mac>();
Log.d(tag," event65");
this.m_adapter = new OrderAdapter(this, R.layout.row, m_orders);
Log.d(tag," 34");
setListAdapter(this.m_adapter);
Log.d(tag," 45");
viewOrders = new Runnable(){
@Override
public void run() {
Log.d(tag," eve");
getOrders();
}
};
Thread thread = new Thread(null, viewOrders, "MagentoBackground");
Log.d(tag," ent7");
thread.start();
m_ProgressDialog = ProgressDialog.show(LearnActivity.this,
"Please wait...", "Retrieving data ...", true);
}
private Runnable returnRes = new Runnable() {
@Override
public void run() {
Log.d(tag," dre");
if(m_orders != null && m_orders.size() > 0){
m_adapter.notifyDataSetChanged();
for(int i=0;i<m_orders.size();i++)
m_adapter.add(m_orders.get(i));
Log.d(tag," ooo");
}
m_ProgressDialog.dismiss();
m_adapter.notifyDataSetChanged();
Log.d(tag," 4567");
}
};
private void getOrders(){
try{
Log.d(tag," yyy");
m_orders = new ArrayList<mac>();
Boolean damn=false;
String sam="hi";
for(int positio=0;positio<index;positio++){
mac o3 = new mac();
String sam1=values[positio];
Log.d(tag,"derk");
o3.setOrderName(sam1);
m_orders.add(o3);
}
Thread.sleep(5000);
Log.i("ARRAY", ""+ m_orders.size());
} catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
runOnUiThread(returnRes);
Log.d(tag,"cfds");
}
private class OrderAdapter extends ArrayAdapter<mac> {
private ArrayList<mac> items;
Boolean testit;
public OrderAdapter(Context context, int textViewResourceId, ArrayList<mac> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(tag," yyt");
View v = convertView;
if (v == null) {
Log.d(tag," ll");
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
mac o = items.get(position);
if (o != null) {
Log.d(tag," uuu");
TextView re=((TextView)v.findViewById(R.id.textView1));
mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
RadioButton newRadioButton = new RadioButton(this);
newRadioButton.setText(R.string.radio_group_snack);
newRadioButton.setId(R.id.snack);
LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
mRadioGroup.addView(newRadioButton, 0, layoutParams);
mRadioGroup.setOnCheckedChangeListener(this);
re.setText(o.getOrderName());
CharSequence fat=re.getText();
String gf=(String)re.getText();
Log.d(gf," 000000");
//String mac=Boolean.toString(testit);
//Log.d(mac," 678990");
//System.out.println(mac," ffff");
//tt.setText("Name: "+o.getOrderName());
// bt.setText("Status: "+ o.getOrderStatus());
}
public void onCheckedChanged(RadioGroup group,int checkedId){
}
return v;
}
}
}