的Java / Android的,多个类 [英] Java/Android, Multiple Classes

查看:138
本文介绍了的Java / Android的,多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid和我有多个类。
我不知道是否有一种方法,我可以以某种方式包括一个主要的类四类。

I am new to Android and I have multiple classes. I was wondering if there is a way that I could somehow include four classes in one major class.

下面是我的例子code的。
我期待着帮助。

Below is example of my code. I am looking forward to help.

这是芬达斯类(大类)

package com.abc.example;

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

public class FindUs extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.findUs);

            Button first = (Button) findViewById(R.id.first);
            Button second = (Button) findViewById(R.id.second);
            Button third = (Button) findViewById(R.id.third);
            Button fourth = (Button) findViewById(R.id.fourth);

            first.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    startActivity(new Intent("com.abc.example.FIRST"));
                }
            });

            second.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    startActivity(new Intent("ccom.abc.example.SECOND"));
                }
            });

            third.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    startActivity(new Intent("com.abc.example.THIRD"));
                }
            });

            fourth.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    startActivity(new Intent("com.abc.example.FOURTH"));
                }
            });             
}


这是次要类(这是有道理只发布一个)。


These are the minor classes (it makes sense only to post one).

package com.abc.example;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class First extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first);

    Button callFirst= (Button) findViewById(R.id.callfirst);
    Button mapFirst= (Button) findViewById(R.id.mapfirst);

    callFirst.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String phoneNumber = "tel:+18000000000";
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse(phoneNumber));
            startActivity(callIntent);

        }
    });

    mapFirst.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String url = "grab google directions for this place";
            Intent mapIntent = new Intent(android.content.Intent.ACTION_VIEW,  Uri.parse(url));
            startActivity(mapIntent);
                }
            });             
}

所以你看,我会为每个类不同的编号和位置。所以,我不确定我是否应该保持四个单独的类或我是否应该包括四个中的一个大类。

So you see, I will have different numbers and location for each class. So I am unsure if I should just keep the four individual classes or if I should include all four within one major class.

感谢。期待更多地了解这从你的球员。

Thanks. Looking forward to learning more about this from your guys.

推荐答案

您应该有一个单独的文件中的每个活动。

You should have every activity in a separate file.

如果您有那些只在一个活动中使用,你可以使用一个内部类或把它下面的另一个(不公开)的辅助类。 活动应该是独立的文件。

If you have helper classes that that are only used in one activity you can use an inner class or put it below the other one (not public). Activities should be separate files.

你可以做的是把code,它有可能成为这两个类也是一个单独的类,使他们都可以使用它。

What you could do is put code that has to be in the two classes also in a separate class so that both of them can use it.

这篇关于的Java / Android的,多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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