2014-12-07 105 views
0

我一直在寻找对这个问题有很多张贴了这个问题之前,但仍不可能得到任何帮助后打开,请帮我解决这个问题,当我按下按钮黑色页面出现,然后应用程序关闭,说它没有响应,即时通讯新手在这里和任何形式的帮助将不胜感激。次活动doesent点击按钮

activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
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.firstapp.MainActivity" > 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView1" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="26dp" 
    android:ems="10" 
    android:inputType="numberPassword" /> 

<EditText 
    android:id="@+id/editText5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText1" 
    android:layout_alignLeft="@+id/editText1" 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text="Enter your Password" 
    tools:ignore="HardcodedText" /> 

<EditText 
    android:id="@+id/editText3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText5" 
    android:layout_alignLeft="@+id/editText5" 
    android:layout_marginBottom="20dp" 
    android:ems="10" 
    android:inputType="textEmailAddress" > 

    <requestFocus android:layout_width="wrap_content" /> 

</EditText> 

<EditText 
    android:id="@+id/editText4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText3" 
    android:layout_alignLeft="@+id/editText3" 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text="Enter your E-mail id" 
    tools:ignore="HardcodedText" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText4" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="36dp" 
    android:src="@drawable/robo" 
    android:contentDescription="@null"/> 

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="38dp" 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text="Welcome To Foodparkk" 
    tools:ignore="HardcodedText" /> 

<Button 
    android:id="@+id/button_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="Login" /> 

</RelativeLayout> 

MainActivity.java
package com.example.firstapp; 

import com.example.firstapp.R; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    final Button button = (Button) findViewById(R.id.button_id); 
    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent i = new Intent(getApplicationContext(),Second.class); 
      startActivity(i); 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
    } 
} 

Second.java
package com.example.firstapp; 

    import android.support.v7.app.ActionBarActivity; 
    import android.os.Bundle; 
    import android.view.Menu; 
    import android.view.MenuItem; 

    public class Second extends ActionBarActivity { 

    @Override 
     protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_second); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.second, menu); 
    return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
    } 
} 

Activity_Second.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
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.firstapp.Second" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 
    </RelativeLayout> 

清单代码

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

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

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

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     </activity> 
     <activity 
     android:name=".Second" 
     android:label="@string/title_activity_second" > 
     </activity> 
    </application> 

    </manifest> 
+0

请张贴代码'秒'活动 – 2014-12-07 19:17:41

+0

类型你得到了错误... – 2014-12-07 19:20:37

+0

第一XML页面打开了,同时运行的应用程序,但只要我按下登录按钮的应用程序关闭并称应用程序没有响应 – Shashwat 2014-12-07 19:23:16

回答

1
public class MainActivity extends ActionBarActivity { //mainactivity class 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
Button button = (Button) findViewById(R.id.button_id); 
button.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
     Intent i = new Intent(MainActivity.this,Second.class); 
     startActivity(i); 
     } 
    }); 
} 

那么你的清单

<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/Theme.Base.AppCompat.Light.DarkActionBar" > // i changed this 
<activity 
    android:name=".MainActivity" 
    android:label="@string/title_activity_main" > 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
    </activity> 
    <activity 
    android:name=".Second" 
    android:label="@string/title_activity_second" > 
    </activity> 
</application> 
如果扩展actionbarActivity其XML应该使用它的风格的,我不wona故事这一点,所以我会repharse它在我的编辑

。简单地说,你的第二个活动不会有风格的设定所以它使用设备的默认主题在你的应用程序设置成复制矿山各自的代码粘贴到你的活动

+0

感谢Elltz .. !! – Shashwat 2014-12-07 19:47:58

-2

它被称为ANR short for Android Not Responding。你的应用在主线程中做了很多处理。考虑使用后台线程或AsyncTask以及ProgressDialog,以便主线程不受处理部分的影响。

Read more关于它的文档。有关更多信息,另请参阅this post