0

I'm following along with this tutorial to build a sample android app using Retrofit and the StackOverflow API. In their MainActivity code on the onClick(View v) method they are referencing the view android.R.id.text1 but I do not see anything in their layout files with the ID of "text1". How can this be?

Also, I'm used to using OnClickListener as an anonymous inner-class. In this example the entire MainActivity implements OnClickListener and onClick(View) is overridden in the class itself. Is there any benefit to doing it this way? They're using a switch statement to determine which layout item is being clicked and putting all the actions in the single onClick(View) method.

Thanks!

intA
  • 2,513
  • 12
  • 41
  • 66
  • `android.R.id.text1` is the built-in `TextView`'s id in android. In your following example, they used built-in layout `simple_list_item 1.xml` , you can see [full file with its id here](https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_list_item_1.xml) – NamNH Jul 05 '17 at 01:20

1 Answers1

1

Citing from here, android.R.id.text1 is an identifier for a TextView.

As for your second question, this post seems to have the answer.

Bonus: Checkout ButterKnife to handle user interactions. Give it a try!

Andy Aldo
  • 890
  • 1
  • 9
  • 24