2011-12-08 42 views
1

您好大家單選按鈕我建立與TextView的並且具有單選按鈕的自定義列表視圖定製列表視圖以編程定義爲I必須把它從一個陣列,並且根據在陣列上,我必須。所以創建它據我能夠創建自定義列表視圖與TextView的,但我不知道如何創建廣播組,單選按鈕,並添加,查看任何幫助,從你們那裏我將非常感激這是低於動態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; 

     } 


    } 
} 
+0

在上面的代碼中這行RadioButton newRadioButton = new RadioButton(this);作爲構造函數RadioButton(LearnActivity.OrderAdapter)的錯誤是未定義的,並且此行爲newRadioButton.setId(R.id.snack);給錯誤的零食不能得到解決或不是field.what它意味着應ineed創建零食不斷 – Ghouse

+0

任何人都可以解釋我對上述錯誤請 – Ghouse

回答

0

是指例子給我的代碼在Excerpt

或作爲替代的解決方案試圖this

+0

感謝您的鏈接AB1209(這一點),但滾動不工作 – Ghouse

+0

我解決了它引入一個ScrollView然後tableLayout作爲它的一個孩子。 – Ghouse