【发布时间】:2014-07-03 09:12:07
【问题描述】:
我想让这段代码更简洁,但我想保留每个 TextViews 引用/名称。
airportCodeText1 = (TextView) findViewById(R.id.airportCode1);
airportCodeText2 = (TextView) findViewById(R.id.airportCode2);
airportText1 = (TextView) findViewById(R.id.airport1);
airportText2 = (TextView) findViewById(R.id.airport2);
departureTime = (TextView) findViewById(R.id.departureTime);
arrivalTime = (TextView) findViewById(R.id.arrivalTime);
flightNunberText = (TextView) findViewById(R.id.flightNoText);
desk = (TextView) findViewById(R.id.desk);
gate = (TextView) findViewById(R.id.gate);
flightNumberTitle = (TextView) findViewById(R.id.flightNoTitle);
deskTitle = (TextView) findViewById(R.id.deskTitle);
gateTitle = (TextView) findViewById(R.id.gateTitle);
【问题讨论】:
-
现在整洁了吗?你在问什么?
-
假设我有 100 个这样的内容,我会淹没我的课在文本中,这将需要很长时间。如果我不需要引用,我会在 for 循环中创建一个数组。我正在为大量 TextView 寻找一种更简洁的初始化方式。
-
请问,你到底为什么会有 100 个!?
-
不要觉得我们在评判你,如果你告诉我们为什么你需要 100 个以及你打算用它们做什么,这可能会帮助我们想出一个解决方案:)
-
看看butterknife:github.com/JakeWharton/butterknife和Android Annotations:github.com/excilys/androidannotations
标签: java android view textview initialization