Android 安卓赢了';不要加载新活动
我试图通过单击按钮将XML中的数据加载到新活动中。问题是,当我点击按钮时,什么都没有发生。它不会崩溃,应用程序只是变得没有响应,仅此而已。它不会在下一个活动中出现。有什么想法吗 主要活动:Android 安卓赢了';不要加载新活动,android,Android,我试图通过单击按钮将XML中的数据加载到新活动中。问题是,当我点击按钮时,什么都没有发生。它不会崩溃,应用程序只是变得没有响应,仅此而已。它不会在下一个活动中出现。有什么想法吗 主要活动: public void onSignupSuccess() { _signupButton.setEnabled(true); setResult(RESULT_OK, null); String toSend = "mailto:" + _nameText.
public void onSignupSuccess() {
_signupButton.setEnabled(true);
setResult(RESULT_OK, null);
String toSend = "mailto:" + _nameText.getText().toString();
String email = _emailText.getText().toString();
String[] toArr = {email};
try {
if(sendEmail()) {
Toast.makeText(this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(MainActivity.this, ListItemsActivity.class);
Log.d(TAG, "Trying to move to the next pane");
startActivity(myIntent);
} else {
Toast.makeText(this, "Email was not sent.", Toast.LENGTH_LONG).show();
}
} catch(Exception e) {
Log.e("MailApp", "Could not send email", e);
}
}
列表活动
public class ListItemsActivity extends Activity {
ListView listView;
private static final String TAG = "ListActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "Trying to create the list activitye");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//* *EDIT* *
this.listView = (ListView) findViewById(R.id.listView1);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_list_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.melisaam.logintest.ListItemsActivity">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:entries="@array/sections" >
</ListView>
</RelativeLayout>
我的列表活动
public class ListItemsActivity extends Activity {
ListView listView;
private static final String TAG = "ListActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "Trying to create the list activitye");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//* *EDIT* *
this.listView = (ListView) findViewById(R.id.listView1);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_list_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.melisaam.logintest.ListItemsActivity">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:entries="@array/sections" >
</ListView>
</RelativeLayout>
我不明白它为什么不起作用。我需要做些额外的事情吗
编辑:
调试时,this.listView为空。所以这一行什么也不做:
this.listView=(listView)findViewById(R.id.listView1)
您已将R.layout.activity\u main
用作ListItemsActivity中的布局。如果这是主要活动的布局,那么这就是问题所在
setContentView(R.layout.activity_main);
您已将
R.layout.activity\u main
用作ListItemsActivity中的布局。如果这是主要活动的布局,那么这就是问题所在
setContentView(R.layout.activity_main);
你调试过了吗?它停在哪一行?并添加我调试过的sendEmail方法。我在编辑的原始帖子中添加了额外的信息。listView始终为空。还添加了sendEmail方法的代码。您调试了吗?它停在哪一行?并添加我调试过的sendEmail方法。我在编辑的原始帖子中添加了额外的信息。listView始终为空。还添加了sendEmail方法的代码就是这样!非常感谢。知道我当前的设置是否可以在视图上显示xml中的特定属性吗?就是这样!非常感谢。知道我当前的设置是否可以在视图上显示xml中的特定属性吗?
setContentView(R.layout.activity_main);