如何连接多个XML文件 [英] How to connect multiple xml files
问题描述
我的应用需要不同的屏幕和每个屏幕应相互连接。例如有5个屏幕,主屏幕,4连接到主屏幕其他屏幕。主屏幕包含4个按钮,转到其他屏幕和其它屏幕有一个按钮,返回到主屏幕。问题是我不能让其他屏幕的ID。我还需要创建4 .java文件为新的屏幕?
My app needs different screens and each screen should be connected with each other. For example there are 5 screens, the main screen, 4 other screens connected to the main screen. The main screen contains 4 buttons to goto other screens and the other screens has a button to go back to the main screen. The problem is i cant get the ids of other screens. And do i need to create 4 .java files for the new screens?
这是code主屏连接到其他:
This is the code for connecting main screen to others:
LayoutInflater inflater;
View one;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.total_assets);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
one = inflater.inflate(R.layout.total_assets,null);
Button home = (Button) findViewById(R.id.goback);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
setContentView(R.layout.activity_acc_soft);
}
});
total_assets是第二屏和actinity_acc_soft是主屏幕。
total_assets is the second screen and actinity_acc_soft is the main screen.
(plz帮助新手到Android)
(plz help newbie to android)
推荐答案
您可以使用 ViewFlipper
。你只需要所有布局添加到您的主布局。然后你就可以在你的 MainActivity.java
通过所有布局。 > ViewFlipper<
但多数民众赞成通过的意见去的旧版本。
You can use ViewFlipper
. You just have to add all layouts to your main layout. And then you can go in your MainActivity.java
through all layouts. >ViewFlipper<
But thats an older version of going through the views.
有一个更好的,更是最新的方法是使用片段
的>片段&LT;
A nicer and more up to date method is using Fragments
>Fragments<
有许多其他的教程和示例。只是谷歌的Android的碎片教程/例如
There are many other tutorials and examples. Just google for "Android fragments Tutorial/example"
这篇关于如何连接多个XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!