链接XML页面布局与 [英] Linking xml pages with layout

查看:81
本文介绍了链接XML页面布局与的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问这个请求的简单 - 但有对我来说,通过布局,而不是code链接以按钮的onClick命令的方式。我想创建一个简单的应用程序,我希望能够使按键和点击都去从一个页到其他。

有可能概述如何使用UI code为DROID网站?

谢谢!


解决方案

  1. 请多少曾经的按钮,你想有。确保如果比你必须指定滚动视图的画面金额。

假设你有你的 R.layout.main.xml 。要了解这一点去 RES /布局/ main.xml中
复制XML,单击鼠标右键,并粘贴在布局文件夹中。然后,它会说重命名。它重命名为你什么都想要。

现在复制这个专门所以可以说你把

  BTN1
BTN2
btn3
btn4
btn5

为使ID标签去对每个按钮的属性和滚动到ID并重新命名的结局BTN1,2,3,4,依此类推。

现在,如果你是放置在你的的.java 文件在的src / com.whateveryounamed.app /无论你什么命名的.java

将低于此code,它会工作。下面是在XML页面5个按钮我的一个例子。

 包com.nashvillekurds.app;进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.Button;公共类kurdishhistoryapp延伸活动{
    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);        按钮BTN1 =(按钮)findViewById(R.id.btn1);
        按钮BTN2 =(按钮)findViewById(R.id.btn2);
        按钮btn3 =(按钮)findViewById(R.id.btn3);
        按钮btn4 =(按钮)findViewById(R.id.btn4);
        按钮btn5 =(按钮)findViewById(R.id.btn5);        btn1.setOnClickListener(新Button.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                意图myIntent =新的Intent();                myIntent.setAction(Intent.ACTION_VIEW);                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                的setContentView(R.layout.btn1);            }
        });        btn2.setOnClickListener(新Button.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                意图myIntent =新的Intent();                myIntent.setAction(Intent.ACTION_VIEW);                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                的setContentView(R.layout.btn2);            }
        });
        btn3.setOnClickListener(新Button.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                意图myIntent =新的Intent();                myIntent.setAction(Intent.ACTION_VIEW);                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                的setContentView(R.layout.btn3);            }
        });
        btn4.setOnClickListener(新Button.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                意图myIntent =新的Intent();                myIntent.setAction(Intent.ACTION_VIEW);                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                的setContentView(R.layout.btn4);            }
        });
        btn5.setOnClickListener(新Button.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                意图myIntent =新的Intent();                myIntent.setAction(Intent.ACTION_VIEW);                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                的setContentView(R.layout.btn5);            }
        });
}}

希望这有助于如果没有抱歉,但你做错了什么......

Excuse the simplicity of this request - but is there a way for me to link onClick commands for buttons through the Layout rather than code. I am trying to create a simple app and I want to be able to make buttons and have clicks go from one "page" to the other.

Is there a site that might overview how to use the UI to code for droid?

Thanks!

解决方案

  1. Make how many ever buttons that you would like to have. Make sure if its more than the screen amount you must assign a scroll view.

assume that you have on your R.layout.main.xml. To find this go to res/layout/main.xml Copy XML, rightclick and paste it in the layout folder. Then it will say Rename. Rename it to what ever you want.

Now copy this specifically so lets say you put

btn1
btn2 
btn3
btn4 
btn5 

To make the id tag go to the properties on each button and scroll to id and rename the ending to btn1 , 2,3, 4, and so on.

Now, if you were to place that in your .java file under src/com.whateveryounamed.app/what ever you named .java

Place this code below and it will work. Below is a example of mine with 5 buttons in xml page.

package com.nashvillekurds.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class kurdishhistoryapp extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btn1 =(Button)findViewById(R.id.btn1);
        Button btn2 =(Button)findViewById(R.id.btn2);
        Button btn3 =(Button)findViewById(R.id.btn3);
        Button btn4 =(Button)findViewById(R.id.btn4);
        Button btn5 =(Button)findViewById(R.id.btn5);

        btn1.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);

                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                setContentView(R.layout.btn1);

            }
        });

        btn2.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);

                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                setContentView(R.layout.btn2);

            }
        });


        btn3.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);

                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                setContentView(R.layout.btn3);

            }
        });


        btn4.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);

                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                setContentView(R.layout.btn4);

            }
        });


        btn5.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);

                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                setContentView(R.layout.btn5);

            }
        });


}}

hope this helped if not sorry but your doing something wrong ...

这篇关于链接XML页面布局与的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆