访问另一个活动的布局

时间:2014-11-07 02:53:29

标签: java android xml

我制作了一个音乐播放器,这是设计快照

My app design

底部的设计对于所有标签都是通用的。

这是tabhost和通用设计的xml文件

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1" >
        <HorizontalScrollView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:scrollbars="none"
            >
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </TabWidget>
        </HorizontalScrollView>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1.00"
            android:divider="@color/list_divider" >

        </FrameLayout>

        <RelativeLayout
            android:id="@+id/Player"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/light_grey"
            android:fadingEdgeLength="5dp"
            android:weightSum="1" >
            <TextView
                android:id="@+id/song_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingBottom="1dp"
                android:text="@string/all_you_need_is_love"
                />
            <LinearLayout
                android:id="@+id/player_art"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_below="@id/song_title"
                android:paddingTop="5dp"
                android:paddingLeft="5dp"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/player_thumbnail"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:background="@drawable/nocover"
                    android:padding="4dp"
                    android:contentDescription="@string/art_image" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/seekbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_toRightOf="@+id/player_art"
                android:layout_alignTop="@+id/player_art"
                android:paddingLeft="5dp"
                >
                <SeekBar
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" 
                    />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_toRightOf="@+id/player_art"
                android:layout_below="@+id/seekbar"
                android:paddingBottom="3dp"
                android:paddingLeft="5dp"
                android:gravity="center_horizontal|center_vertical"
                >
                <ImageButton
                    android:id="@+id/previous"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:padding="2dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/rsz_previous"
                    android:background="@drawable/custom_button"
                    android:contentDescription="@string/play_button"
                />

                <ImageButton
                    android:id="@+id/play"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:padding="2dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/rsz_play"
                    android:background="@drawable/custom_button"
                    android:contentDescription="@string/play_button"
                />
                <ImageButton
                    android:id="@+id/next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/rsz_next"
                    android:layout_marginLeft="10dp"
                    android:padding="2dp"
                    android:scaleType="centerCrop"
                    android:background="@drawable/custom_button"
                    android:contentDescription="@string/play_button"
                />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</TabHost>

和另一个xml文件用于显示名为music_tab.xml的歌曲

这是我的java文件,Allsong包含所有歌曲标题

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
MainView = (ViewGroup) inflater.inflate(R.layout.music, null, false);

SongName = (TextView) MainView.findViewById(R.id.song_title);

SongName.setText(Allsong.get(position));
String prev = SongName.getText();

它没有设置设计中的歌曲Title,而是设置了之前由setText()方法设置的值的prev字符串。 请有人帮帮我。谢谢。

2 个答案:

答案 0 :(得分:0)

我也对此事进行了很多研究而没有结果。我得出的结论是,类只能访问布局中存在的那些小部件。

答案 1 :(得分:0)

根据我的知识,这是不可能的!

  • 假设您在 ClassA
  • 中有WIDGET-A
  • 要在 ClassB 中访问WIDGET-A,您必须通过 对象从 ClassA ClassB (例如:使用意图)然后 操纵它