2013-10-30 3 views
0
  • 화면에 질문을 남기면서 질문에 대한 답을하게됩니다 A 버튼을 표시하는
  • 미리 정의 된 질문을 제시 할 영역을 클릭
  • 대답을 표시 할 영역
  • 다음 질문과 함께이 화면과 동일한 형식으로 변환되는 버튼
  • 앱을 끝내게하는 버튼 (a (3)으로의 천이)

버튼 클릭만으로 다른 질문/답변 쌍으로 작동하려면 화면 1에서 화면 2로 전환하려고 시도하십시오. 오류가있는 화면과 활동을 전환하는 것 이외에 다른 작업을 수행하려는 경우 알려주십시오. (넣다 필요)불행하게도 버튼 작동이 중지되었습니다 (프로젝트 이름)

package com.example.androidassignment2; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.content.Intent; 

public class AndroidAssignment2 extends Activity { 

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

     Button next = (Button) findViewById(R.id.QButton); 
     next.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       Intent intent = new Intent(); 
       setResult(RESULT_OK, intent); 
       finish(); 
      } 
     }); 

    } 

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

} 

레이아웃 파일

<LinearLayout 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:orientation="vertical" > 

<TextView android:id="@+id/Questions" 
    android:layout_weight="1" 
    android:layout_width="wrap_content" 
    android:layout_height="0dip" 
    android:text="@string/Q2" /> 

<Button android:id="@+id/QButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_question" /> 

<Button android:id="@+id/AButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_send" /> 

<TextView android:id="@+id/Answers" 
    android:layout_weight="1" 
    android:layout_width="wrap_content" 
    android:layout_height="0dip" 
    android:hint="@string/A2" /> 

<Button android:id="@+id/QuitButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_quit" /> 


</LinearLayout> 

활동 한 파일은

package com.example.androidassignment2; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.content.Intent; 

public class MainActivity extends Activity { 

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


     Button next = (Button) findViewById(R.id.QButton); 
     next.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       Intent myIntent = new Intent(view.getContext(), AndroidAssignment2_1.class); 
       startActivityForResult(myIntent, 0); 
      } 
     }); 

    } 

    @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; 
    } 
} 
당신은 새로운 활동을 시작
+3

항상 게시하시기 바랍니다 로그 캣 스택 추적을 사용하는 것입니다. 어떻게하는지 모르면 물어보십시오. – Simon

답변

0
Intent myIntent = new Intent(view.getContext(), AndroidAssignment2_1.class); 
startActivityForResult(myIntent, 0); 

, 가장 가능성있는 원인이되지 않은 점이다 매니페스트에서 선언되었습니다. 당신의 AndroidManifest.xml`에서

,이 같은 것을 추가해야합니다

<activity 
    android:name="your.package.name.AndroidAssignment2_1" /> 

이것은 <application> 태그 내부에있는 것입니다.

+1

패키지 이름의 첫 단어 앞에 점이 찍혔습니다. > : | – Learning2Code

0

startActivityForResult()을 사용하고 있지만 Activity에서 onActivityForResult() 메서드를 재정의하지 마십시오. 당신은 단지 startActivity()을 사용하고 두 번째 Activity에서 setResult()을 제거하도록 변경할 수 있습니다. 이 방법으로 문제가없는 경우

Button next = (Button) findViewById(R.id.QButton); 
    next.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      Intent myIntent = new Intent(view.getContext(), AndroidAssignment2_1.class); 
      startActivity(myIntent); 
     } 
    }); 

다음 로그 캣을 게시 (당신이 충돌이 항상하는 경우)와 Activity이 decalred되어 있는지 확인하시기 바랍니다.

는 지금까지 다른 질문

오류 인 화면과 활동을 전환하는 것보다이 다른 작업을 수행 할 수 어쨌든이있는 경우로 알려 주시기 바랍니다.

단순히 텍스트를 변경하는 경우 동일한 Activity에 머물러 있고 TextView의 텍스트를 변경할 수 있습니다. 원하는 경우 질문과 대답을 Array 또는 DB에 저장할 수 있으며 원할 경우 카운터를 유지하고 클릭 할 때마다 텍스트를 변경할 수 있습니다. 당신이 원하는 경우 첫 번째 함께 갈 수

또 다른 옵션은,하는 ViewPager

관련 문제