Я новичок в Android, и у меня есть несколько классов.
Мне было интересно, можно ли как-нибудь включить четыре класса в один основной класс.
Ниже приведен пример моего кода.
Я с нетерпением жду помощи.
Это класс FindUs (основной класс)
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"));
}
});
}
Это второстепенные классы (имеет смысл только опубликовать один).
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);
}
});
}
Итак, вы видите, у меня будут разные номера и местоположение для каждого класса. Поэтому я не уверен, стоит ли мне просто оставить четыре отдельных класса или включить все четыре в один основной класс.
Спасибо. Будем рады узнать больше об этом от ваших ребят.