Я хотел бы показать все доступные сеансы из базы данных определенным образом. Вот что я создал в создателе.Как конвертировать xml-позиционирование в java-код?
Я хотел бы показать неопределенное количество фильмов, так что я генерировать это в Java. Как преобразовать xml-позиционирование в java? Какие классы использовать? Вот XML-файл:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="78dp"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Spectre (2015)"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Great Britain 2D Subtitles 121 min"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="18:45"
android:id="@+id/textView3"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Вот Java-код:
for (int i = 0; i < 20; i++) {
RelativeLayout relLayout = new RelativeLayout(this);
TextView textView = new TextView(this);
textView.setText("Big black text:" + i);
textView.setTextSize(22);
textView.setTextColor(Color.BLACK);
TextView textView1 = new TextView(this);
textView1.setText("Middle grey text:"+i);
textView1.setTextSize(18);
textView1.setTextColor(Color.GRAY);
TextView textView2 = new TextView(this);
textView2.setText("Right down corner:" + i);
textView2.setTextSize(20);
textView2.setTextColor(Color.BLACK);
relLayout.addView(textView);
relLayout.addView(textView1);
relLayout.addView(textView2);
relLayout.setId(i);
final int id_ = relLayout.getId();
LinearLayout layout = (LinearLayout) findViewById(R.id.llayout);
layout.addView(relLayout);
relLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(getApplicationContext(),
"Button clicked index = " + id_, Toast.LENGTH_SHORT)
.show();
}
});
}
Спасибо за ваш ответ, это поможет мне много , – pawkondr