Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将xml定位转换为java代码?_Java_Android - Fatal编程技术网

如何将xml定位转换为java代码?

如何将xml定位转换为java代码?,java,android,Java,Android,我想以一种特定的方式显示数据库中所有可用的座位。这是我在creator中设计的 我想显示未定义数量的电影,所以我用java生成它。如何将xml定位转换为java?使用哪些类?以下是xml文件: <RelativeLayout android:layout_width="match_parent" android:layout_height="78dp" android:layout_gravity="center_horizontal"&g

我想以一种特定的方式显示数据库中所有可用的座位。这是我在creator中设计的

我想显示未定义数量的电影,所以我用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();
            }
        });
    }
for(int i=0;i<20;i++){
RelativeLayout relLayout=新的RelativeLayout(此);
TextView TextView=新的TextView(此);
setText(“黑色大文本:+i”);
textView.setTextSize(22);
textView.setTextColor(Color.BLACK);
TextView textView1=新的TextView(此);
textView1.setText(“中间灰色文本:+i”);
textView1.setTextSize(18);
textView1.setTextColor(Color.GRAY);
TextView textView2=新的TextView(此);
textView2.setText(“右下角:+i”);
textView2.setTextSize(20);
textView2.setTextColor(Color.BLACK);
relLayout.addView(textView);
relLayout.addView(textView1);
relLayout.addView(textView2);
relLayout.setId(i);
final int id_u2;=relLayout.getId();
LinearLayout布局=(LinearLayout)findViewById(R.id.llayout);
layout.addView(relLayout);
relLayout.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图){
Toast.makeText(getApplicationContext(),
“按钮点击索引=“+id\u,Toast.LENGTH\u SHORT”)
.show();
}
});
}

看看下面的课程

你的方法是错误的,因为如果你有很多行,应用程序就会崩溃

当然,您需要自定义列表项,这通常是一个热门话题,您可以通过谷歌搜索出来,但以下是其中之一:


谢谢你的回答,这对我会有很大帮助。