我有一个主要活动(mottoscreen),之后会打开一个名为circle的活动,然后从该活动中打开其他两个活动之一(sc_activity和or_activity)。我已经为它编写了代码,但是当点击圈子活动中的按钮时,下一个活动没有显示出来。
圈子Java文件 -
package com.apsdevelopers.mr.meteout;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
public class circles extends mottoscreen {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.circles);
}
public void onButtonClick(View v)
{
if (v.getId() == R.id.GOsc)
{
Intent I = new Intent(circles.this, sc_activity.class);
startActivity(I);
}
else if (v.getId() == R.id.GOor)
{
Intent j = new Intent(circles.this, or_activity.class);
startActivity(j);
}
}
}
Sc_activity Java文件 -
package com.apsdevelopers.mr.meteout;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class sc_activity extends mottoscreen
{
EditText name, ph, address, mass, thing;
Button msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sc_activity);
name = (EditText)findViewById(R.id.name);
EditText p = (EditText)findViewById(R.id.pin);
String pinc = p.getText().toString();
final int apsnumber= Integer.parseInt("8763597264");
if (pinc.equals("753001") || pinc.equals("753002") || pinc.equals("753003") || pinc.equals("753004") || pinc.equals("753005") || pinc.equals("753006") || pinc.equals("753007") || pinc.equals("753008") || pinc.equals("753009")) {
ph = (EditText)findViewById(R.id.ph);
address = (EditText)findViewById(R.id.address);
mass = (EditText)findViewById(R.id.mass);
thing = (EditText)findViewById(R.id.thing);
msg = (Button)findViewById(R.id.msg);
msg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String number = ph.getText().toString();
String message1 = name.getText().toString();
String message2 = address.getText().toString();
String message3 = mass.getText().toString();
String message4 = thing.getText().toString();
Intent i = new Intent(getApplicationContext(), sc_activity.class);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(String.valueOf(apsnumber), null, number+message1 + message2 + message3 + message4, pIntent, null);
Toast.makeText(getApplicationContext(), "Form sent successfully ! , now click on DONE",
Toast.LENGTH_LONG).show();
}
});
}
else
{
Toast.makeText(getApplicationContext(), "ERROR: WE DONOT COVER THE PINCODE ENTERED BY YOU, PLZ ENTER A VALID PINCODE OF (CTC, ODISHA)",
Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
public void onButtonClick(View v)
{
if (v.getId() == R.id.msg)
{
Intent I = new Intent(sc_activity.this, th_activity.class);
startActivity(I);
}
}
}
Sc_activity XML文件 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#9acef6fe"
android:id="@+id/sc_activity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="NAME"
android:ems="10"
android:id="@+id/name"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:imeOptions="actionNext"
android:textColor="#d4375a5c" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/ph"
android:layout_below="@+id/name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="PHONE NUMBER"
android:imeOptions="actionNext"
android:textColor="#d4375a5c" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="E.g.-5kg, 100 bottles... "
android:id="@+id/textView12"
android:layout_below="@+id/mass"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="E.g.- metal scrap+newspapers, bottles+tyres...+"
android:id="@+id/textView11"
android:layout_below="@+id/thing"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="@+id/address"
android:text="ADDRESS"
android:imeOptions="actionNext"
android:textColor="#d4375a5c"
android:layout_below="@+id/pin"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="36dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thing"
android:text="THING"
android:imeOptions="actionNext"
android:textColor="#d4375a5c"
android:layout_below="@+id/address"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="38dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/mass"
android:text="AMOUNT"
android:imeOptions="actionDone"
android:textColor="#d4375a5c"
android:layout_below="@+id/textView11"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="39dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/pin"
android:layout_marginTop="36sp"
android:text="PINCODE"
android:textColor="#d4375a5c"
android:layout_below="@+id/ph"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEND MESSAGE"
android:id="@+id/msg"
android:background="#e33a9179"
android:textColor="#ffffff"
android:textSize="20sp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/thing"
android:layout_alignRight="@+id/textView11"
android:layout_alignEnd="@+id/textView11" />
</RelativeLayout>
Or_activity Java文件 -
package com.apsdevelopers.mr.meteout;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class or_activity extends mottoscreen
{
EditText nam, pho, addres, mas, thinge;
Button msg2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.or_activity);
nam = (EditText) findViewById(R.id.nam);
EditText p = (EditText) findViewById(R.id.pin1);
String pinc = p.getText().toString();
final int apsnumber= Integer.parseInt("8763597264");
if (pinc.equals("753001") || pinc.equals("753002") || pinc.equals("753003") || pinc.equals("753004") || pinc.equals("753005") || pinc.equals("753006") || pinc.equals("753007") || pinc.equals("753008") || pinc.equals("753009")) {
pho = (EditText) findViewById(R.id.ph);
addres = (EditText) findViewById(R.id.address);
mas = (EditText) findViewById(R.id.mass);
thinge = (EditText) findViewById(R.id.thing);
msg2 = (Button) findViewById(R.id.msg2);
msg2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String number = pho.getText().toString();
String message1 = nam.getText().toString();
String message2 = addres.getText().toString();
String message3 = mas.getText().toString();
String message4 = thinge.getText().toString();
Intent i = new Intent(getApplicationContext(), or_activity.class);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(String.valueOf(apsnumber), null, number+message1 + message2 + message3 + message4, pIntent, null);
Toast.makeText(getApplicationContext(), "Form sent successfully ! , now click on DONE",
Toast.LENGTH_LONG).show();
}
});
}
else
{
Toast.makeText(getApplicationContext(), "ERROR: WE DONOT COVER THE PINCODE ENTERED BY YOU, PLZ ENTER A VALID PINCODE OF (CTC, ODISHA)",
Toast.LENGTH_LONG).show();
}
}
public void onButtonClick(View v)
{
if (v.getId() == R.id.msg2)
{
Intent I = new Intent(or_activity.this, th_activity.class);
startActivity(I);
}
}
}
Or_activity XML文件 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#9acef6fe"
android:id="@+id/or_activity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="NAME"
android:ems="10"
android:id="@+id/nam"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:imeOptions="actionNext"
android:textColor="#d4375a5c" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/pho"
android:text="PHONE NUMBER"
android:imeOptions="actionNext"
android:textColor="#d4375a5c"
android:layout_below="@+id/nam"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/pin1"
android:text="PINCODE"
android:layout_below="@+id/pho"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="43dp"
android:imeOptions="actionNext"
android:textColor="#d4375a5c" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="@+id/addres"
android:text="ADDRESS"
android:imeOptions="actionNext"
android:textColor="#d4375a5c"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/mas"
android:text="AMOUNT"
android:imeOptions="actionNext"
android:textColor="#d4375a5c"
android:layout_marginTop="25dp"
android:layout_below="@+id/textView11"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="E.g.- toys , clothes ... "
android:id="@+id/textView11"
android:layout_below="@+id/thinge"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thinge"
android:text="THING"
android:imeOptions="actionDone"
android:textColor="#d4375a5c"
android:layout_below="@+id/addres"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEND MESSAGE"
android:id="@+id/msg2"
android:background="#e33a9179"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView11"
android:layout_alignEnd="@+id/textView11"
android:layout_toRightOf="@+id/thinge"
android:layout_toEndOf="@+id/thinge" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="E.g.-5 books,2 cricket bats..."
android:id="@+id/textView12"
android:layout_below="@+id/mas"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
请指导我在代码中出错的地方。
答案 0 :(得分:1)
请您在代码中查看以下内容:
android:onClick="onButtonClick"
?