그렇다면 ScrollView가 다소 불편하거나 (의심스러워) 다른 방법이있는 것 같습니다. 여기 내 코드가있다. 폭탄이 터지면 (두 번째로 루프를 통과 함) 주석 처리됩니다.ScrollView에 여러 개의보기를 추가 할 수 있습니까?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ondemandandautomatic_dynamicauthorize);
ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost);
// Contacts data snippet adapted from
// http://saigeethamn.blogspot.com/2011/05/contacts-api-20-and-above-android.html
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// Create a Linear Layout for each contact?
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.weight = 1.0f;
CheckBox cbOnDemand = new CheckBox(getApplicationContext());
cbOnDemand.setTag(id);
cbOnDemand.setLayoutParams(llp);
llay.addView(cbOnDemand);
CheckBox cbTime = new CheckBox(getApplicationContext());
cbOnDemand.setTag(id);
cbTime.setLayoutParams(llp);
llay.addView(cbTime);
CheckBox cbSpace = new CheckBox(getApplicationContext());
cbOnDemand.setTag(id);
cbSpace.setLayoutParams(llp);
llay.addView(cbSpace);
TextView tv = new TextView(getApplicationContext());
tv.setTag(id);
tv.setText(name);
tv.setLayoutParams(llp);
llay.addView(tv);
svh.addView(llay); // it transports me to Eclipse's Debug perspective when I hit this line the SECOND time around.
// One cat on stackOverflow said to do this, another said it
// would be unnecessary
svh.invalidate();
}
}
}
도움 주셔서 감사합니다. 옵션 2 (이 첫 번째 찌르다) 문제가 런타임에 각 확인란을 프로그래밍 방식으로 식별 할 수있는 방법을 알아낼 수 없다는 것, 옵션 A와 함께 갈 것입니다. 어느 행이 클릭되고 있는지. 확인란마다 연락처 ID에 해당하는 태그 값이 있어야하므로 각 연락처에 대해 어떤 옵션을 선택했는지 알 수 있습니다. 그래서 동적으로 생성되는 위젯 경로를 방문한 후 체크 박스 (및 textView) 위젯을 만드는 루프에 태그를 추가 할 수 있습니다. –
왜 옵션 2가 선호됩니까? – Johan