Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.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
Java 在xml中显示图像选项,并在第二次启动时更改主活动_Java_Android_Xml - Fatal编程技术网

Java 在xml中显示图像选项,并在第二次启动时更改主活动

Java 在xml中显示图像选项,并在第二次启动时更改主活动,java,android,xml,Java,Android,Xml,我想学习如何创建安卓应用程序,但我很困惑: 1.首次启动我的应用程序时,将显示viewpagers img_btn ice、img_btn jelly。当点击img_按钮时,会显示profil.xml中选择的图像,是否有任何解决方案可以用1个xml完成,或者我必须为每个按钮创建2个xml 2.如果用户选择了img_按钮,则主_活动将更改为profil.xml,因此第二次启动将显示profil.xml。我该怎么做 main_activity.xml <LinearLayout xmlns:a

我想学习如何创建安卓应用程序,但我很困惑:

1.首次启动我的应用程序时,将显示viewpagers img_btn ice、img_btn jelly。当点击img_按钮时,会显示profil.xml中选择的图像,是否有任何解决方案可以用1个xml完成,或者我必须为每个按钮创建2个xml

2.如果用户选择了img_按钮,则主_活动将更改为profil.xml,因此第二次启动将显示profil.xml。我该怎么做

main_activity.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#000000"
>
<TextView
    android:text="Choose char"
    android:textSize="25dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#1e00ff"/>
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_ViewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"/>
page2.xml和page2.java与page1相同
英语不是我的第一语言,所以请原谅我的错误。

我不知道你扩展了什么片段。导入android.support.v4.app.Fragment;或者导入android.app.Fragment;下面的示例假设您使用support.v4

public void replaceFragment(Fragment fragment, String title) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, fragment)
                .addToBackStack(title)
                .commit();
    }

    public void addFragment(Fragment fragment, String title) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.content_frame, fragment, title)
                .addToBackStack(title)
                .commit();
    }

您最好有2个xml(例如page1.xml,page2.xml)和两个扩展片段的类,您可以使用上面的函数首先添加一个片段,然后在打开新片段时使用replace。请注意,在给定的函数中有一个R.id.content_框架。从main_activity.xlm中,创建一个线性布局,将其命名为content_frame,它将保存打开的片段。然后在page1.xml上放置一个按钮,在page2.xml中放置一个ImageView,当单击page1上的按钮时。使用replaceFragment打开page2.xml

可以显示您的xlm吗。和代码。还有,你想把你的照片放在什么上面?在寻呼机上?或者一些imageView?查看共享性能。您可以将图像url传递给第二个活动,该活动在单击按钮后显示您的图像<代码>意图=新意图(此,Activity2.class);String imageUrl=“将图像url放在此处”;intent.putExtra(“url”,imageUrl);星触觉(意向)我希望图像显示在imageview上,但我不知道如何在另一个xml中显示所选图像,谢谢
import android.support.v4.app.*;
import android.view.*;
import android.os.*;

public class page1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,   Bundle savedInstanceState)
{
    View v=inflater.inflate(R.layout.halaman_1, container,false);
    return v;
}
}
public void replaceFragment(Fragment fragment, String title) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, fragment)
                .addToBackStack(title)
                .commit();
    }

    public void addFragment(Fragment fragment, String title) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.content_frame, fragment, title)
                .addToBackStack(title)
                .commit();
    }