2016-11-19 53 views
0

我试图从按钮单击一个新的活动中的XML加载数据。问题是,当我点击按钮时没有发生任何事情。它不会崩溃,应用程序只是变得没有响应,这就是全部。它不会去下一个活动。有任何想法吗?Android不会加载新活动

主要活动:

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> 

array.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string-array name="sections"> 
     <item >Pro Constructive</item> 
     <item >Con Constructive</item> 
     <item >1st Speaker Cross</item> 
     <item >Pro Rebbutal</item> 
     <item >Con Rebuttal</item> 
     <item >2nd Speaker Cross</item> 
     <item >Pro Summary</item> 
     <item >Con Summary</item> 
     <item >Grand Cross</item> 
     <item >Pro Final Focus</item> 
     <item >Con Final Focus</item> 
    </string-array> 
</resources> 

而我的清单

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.melisaam.logintest"> 

    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".ListItemsActivity" /> 
     <activity android:name=".SingleListItem"></activity> 
    </application> 

</manifest> 

这是我的日志。我不能做任何事情。

D/ListActivity: Trying to create the list activitye 
D/TextView: setTypeface with style : 0 
D/Activity: performCreate Call Injection manager 
I/InjectionManager: dispatchOnViewCreated > Target : com.example.melisaam.logintest.ListItemsActivity isFragment :false 
D/SecWifiDisplayUtil: Metadata value : SecSettings2 
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{64e0b62 I.E...... R.....ID 0,0-0,0} 
V/RenderScript: 0x7f613b7000 Launching thread(s), CPUs 8 
D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1 
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
I/Timeline: Timeline: Activity_idle id: [email protected] time:249820080 
V/ActivityThread: updateVisibility : ActivityRecord{3c16e43 [email protected] {com.example.melisaam.logintest/com.example.melisaam.logintest.MainActivity}} show : false 
D/ViewRootImpl: #3 mView = null 

我不明白为什么它不工作。我需要额外做些什么吗?

编辑:

public boolean sendEmail() { 
     try { 
      Intent sendIntent = new Intent(Intent.ACTION_SEND); 
      sendIntent.setType("plain/text"); 
      sendIntent.setData(Uri.parse("[email protected]")); 


sendIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail"); 
     sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Registration Trucks for Sale"); 
String message = "I'd like to register on your site with the following information" + "\n" + 
       "Username: " + _nameText.getText().toString() + "\n" + 
       "Email: " + _emailText.getText().toString() + "\n" + 
       "Password: " + _passwordText.getText().toString() + "\n" + 
       "Thank you!"; 
     sendIntent.putExtra(Intent.EXTRA_TEXT, message); 
     startActivity(sendIntent); 
    } catch (Exception e) { 
     return false; 
    } 
    return true; 
} 

在调试中,this.listView为空。因此,此行不执行任何操作:this.listView = (ListView) findViewById(R.id.listView1);

+0

你调试了吗?在哪条线停止?并添加sendEmail方法 –

+0

我调试它。我在编辑的原始文章中添加了额外的信息。 listView始终为空。还添加了sendEmail方法的代码 – Mocktheduck

回答

2

您已在ListItemsActivity中使用R.layout.activity_main作为布局。如果这是主要活动的布局,那么这就是问题

setContentView(R.layout.activity_main); 
+0

这就是它!谢谢! – Mocktheduck

+0

任何想法,如果我的当前设置可能显示在我的XML的特定属性的视图? – Mocktheduck