【问题标题】:Android ListView Custom ArrayAdapterAndroid ListView 自定义 ArrayAdapter
【发布时间】:2010-03-11 22:37:03
【问题描述】:

大家好,我正在查看这段代码,但我很难理解 super 关键字的作用。

我知道它会调用超类构造函数,但在这个例子中似乎没有超类,所以我很困惑。

所以有 customArray 构造函数,然后是它的调用 super 但在什么上?

public class customArray extends ArrayAdapter<String> {


 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 i = new Intent(this.class,Alarm.class);


                startActivity(i);

                //   Alarm al = new Alarm(); //
                     b1.setText("alarm set");



                }
           });

      }

【问题讨论】:

  • customArray extends ArrayAdapter&lt;String&gt;,所以这就是你的超类。 super(cont, _resource, items) 正在调用一个接受三个参数的超类构造函数。

标签: android android-listview


【解决方案1】:

你确定不是 ArrayAdapter 吗?在此处查看构造函数:http://developer.android.com/reference/android/widget/ArrayAdapter.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    相关资源
    最近更新 更多