2010-02-21 147 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