2010-02-21 116 views
1

Hi我得到了一個自定義列表視圖,並試圖啓動一個新的按鈕點擊活動,但是當我嘗試設置一個意圖時發生,我想這是因爲我的自定義數組類沒有擴展活動。這些按鈕觸發警報設置。有什麼辦法可以讓我有意在這堂課上班?Android自定義列表視圖

以下是我的班級代碼。

public class customArray extends ArrayAdapter<String> { 
SatMain sm = new SatMain(); 


int resource; 

public customArray(Context cont, int _resource, List<String> items) { 
    super(cont, _resource, items); 
    resource = _resource; 

} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    RelativeLayout rl; 

    String prod = getItem(position); 
    if (convertView == null) { 
     rl = new RelativeLayout(getContext()); 
     LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
       Context.LAYOUT_INFLATER_SERVICE); 
     vi.inflate(resource, rl, true); 
    } else { 
     rl = (RelativeLayout) convertView; 
    } 
    TextView t1 = (TextView) rl.findViewById(R.id.text12); 
    t1.setText(prod); 
    final Button b1 = (Button) rl.findViewById(R.id.widget29); 

    b1.setText("efwrf"); 

    if (position == 2) { 

     b1.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 


       Intent intent = new Intent(customArray.class, SatMain.class); 
        startActivity(intent); 


       b1.setText("alarm set"); 



      } 
     }); 

    } 

    if (position == 0) { 

     b1.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 

      } 
     }); 
     b1.setText("number 0"); 
    } 

    return rl; 
} 

}

+0

發生了什麼錯誤? – 2010-02-21 18:57:22

+0

它只是sais意圖的構造函數是未定義的(沒有運行它作爲它的編譯錯誤) – SamB09 2010-02-21 19:11:13

回答

1

這只是最高審計機關,對 意圖的構造是不確定的(還沒有運行它 它的編譯錯誤)

那麼,你需要使用適當的Intent構造函數。而不是使用customArray.class(這是Class)或customArray(這是ArrayAdapter),您需要提供Context。你在這個代碼中使用了getContext()幾個地方 - 我想這裏也使用它。

+0

啊輝煌它的工作現在謝謝。 – SamB09 2010-02-21 19:23:02