使用单独的XML布局不同DATAS多种活动布局、多种、不同、XML

2023-09-12 04:50:39 作者:口喜

我知道这是一个很基本的问题,但作为一个新手,我不能去解决它。 所以,我想必须使用相同的XML布局多重活动(包括例如1的ImageButton,以及多个textviews用不同的ID)。现在,对于每一个活动,我希望他们能够查看相同的布局,但覆盖数据独有的每一项活动的意见。什么是做到这一点的最好方法是什么?而且,该ImageButton的应该打开一个视频播放器不同的网址(YouTube的链接)。

I know this is a very basic question, however as a newbie i cant get to work around it. So, I want to have multiple activities to use same the xml layout(consist for example of 1 imagebutton, and multiple textviews with different IDs). Now, for every activity, I want them to view the same layout but override the views with data unique to every activity. What is the best way to do this? And also, the imagebutton should open different URLs in a video player(youtube links).

和可有人告诉我什么是学习机器人编程最实用的方法是什么?

And can somebody tell me what is the most practical way to learn android programming?

更新 这是我目前的code:

UPDATE This is my current code:

public class TemakiActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contentviewer);
}

}

例如我有一个ID为descriptionviewer一个TextView,并与ID为录象按钮,现在,你怎么了code那些?

For example I have a textview with ID "descriptionviewer", and a button with ID "videolink", now, how do you code those in?

推荐答案

您可以共享相同的布局文件和意见,每一项活动的onCreate(..)方法设置的属性。

You can share the same layout file and the set the attributes for views in the onCreate(..) method of each activity.

如果你要打开的每个图像按钮不同的网址,你可以在运行时,如下所示设置

If you want a different URL to open for each image button you could set it at runtime as follows

public void onCreate(Bundle b) {

    Button button =(Button)findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            //different action for each activity
        }
    });
}