2014-12-07 7 views
0

이 질문을 게시하기 전에이 문제에 대해 많은 조사를 해본 적이 있지만 여전히 도움을 얻을 수는 없지만 친절하게도이 문제를 해결할 때 도움이됩니다. 나타나는 다음 응용 프로그램이 응답하지 않는, 여기에 초보자와 어떤 종류의 도움을 말하는 종료됩니다 감사합니다.버튼을 클릭하면 두 번째 활동이 열립니다.

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> 
,536 MainActivity.java
<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> 

activity_main

명시 코드

<?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

'Second 활동'코드를 –

+0

에 게시하십시오. 오류가 발생했습니다 ... –

+0

응용 프로그램을 실행하는 동안 첫 xml 페이지가 열리지 만 로그인 버튼을 누르면 응용 프로그램이 응답하지 않는다는 메시지가 닫힙니다 – Shashwat

답변

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

-2

Android 응답이 없으므로 ANR 단락이라고합니다. 앱이 주 스레드에서 많은 처리를하고 있습니다. 주 스레드가 처리 부분의 영향을받지 않도록 ProgressDialog와 함께 백그라운드 스레드 또는 AsyncTask를 사용하는 것이 좋습니다.

Read more 문서에 나와 있습니다. 자세한 내용은 this post을 참조하십시오.

관련 문제