Android ListView with onClick items

前端 未结 9 1589
梦如初夏
梦如初夏 2020-11-27 03:33

I\'m a new programmer and new in Android. I\'m using this example http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ and it works great.

9条回答
  •  离开以前
    2020-11-27 03:57

    You should definitely extend you ArrayListAdapter and implement this in your getView() method. The second parameter (a View) should be inflated if it's value is null, take advantage of it and set it an onClickListener() just after inflating.

    Suposing it's called your second getView()'s parameter is called convertView:

    convertView.setOnClickListener(new View.OnClickListener() {
      public void onClick(final View v) {
        if (isSamsung) {
          final Intent intent = new Intent(this, SamsungInfo.class);
          startActivity(intent);
        }
        else if (...) {
          ...
        }
      }
    }
    

    If you want some info on how to extend ArrayListAdapter, I recommend this link.

提交回复
热议问题