[英]Access Layout of another activity
I made a music player and here is the design snapshot 我做了一个音乐播放器,这是设计快照
design at the bottom is common for all tabs. 底部的设计对于所有标签都是通用的。
here is the xml file for tabhost and common 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>
and another xml file is used for showing songs named music_tab.xml 另一个xml文件用于显示名为music_tab.xml的歌曲
Here is my java file and Allsong contains all songs title 这是我的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();
It does not set the song Title on design but the prev string that is having the value previously set by setText() Method. 它不会在设计中设置歌曲标题,而是在设置之前具有setText()方法设置的值的上一个字符串。 Please anyone help me.Thanks in advance. 请任何人帮助我。谢谢。
I too have researched on this thing a lot with no result. 我也对此事做了很多研究,但没有结果。 The conclusion I came upon was that a class can access only those widgets that are present in the layout which it inflates. 我得出的结论是,一个类只能访问其展开的布局中存在的那些小部件。
As per my Knowledge, This is not possible ! 据我所知,这是不可能的!
WIDGET-A
in ClassA 假设您在ClassA中拥有WIDGET-A
WIDGET-A
in say ClassB , you have to pass the object from ClassA to ClassB (Eg: using intents) and then manipulate it 为了访问ClassB中的 WIDGET-A
,您必须将对象从ClassA传递到ClassB (例如:使用意图),然后对其进行操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.