У меня есть следующий макет в моей деятельностиДобавление контента в ScrollView динамически
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/topHeading"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal|center_vertical">
<LinearLayout
android:id="@+id/scrollViewlinearlayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal">
<!--
Content will be dynamically added to this portion.
-->
</LinearLayout>
</HorizontalScrollView>
В моем коде деятельности я надуть вид и добавить к выше макете
LinearLayout scrollViewLinearLayout=(LinearLayout)root.findViewById(R.id.scrollViewlinearlayout);
for(int i=0;i<10;i++){
View view =inflater.inflate(R.layout.lesson_row,null,false);
Button b1=(Button) view.findViewById(R.id.button);
b1.setOnClickListener(this);
scrollViewLinearLayout.addView(view);
}
Теперь это работает отлично. У меня 10 макетов в моем макете scrollview. Теперь R.layout.lesson_row
содержит кнопки, на которые я хочу нажать. Я могу легко добавить кнопку прослушивания кнопки к кнопке, но какая кнопка из 10 макетов была нажата?
http://stackoverflow.com/a/15732374/1380752 – codeMagic
или просто использовать ListView вместо этого. – Selvin
Его горизонтальная компоновка. – AndroidDev