한 활동에서 사용자로부터 가져온 데이터를 다른 활동에 표시하는 방법에 대한 자습서를 보았습니다. 그리고 내 자신의 버전을 제안하려고했습니다. 매우 제한된 지식). 여기 버튼 클릭으로 새로운 활동으로 이동할 수 없습니다.
는package kk.screen;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class ScreenActivity extends Activity {
/** Called when the activity is first created. */
EditText inputName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void btnclick(View view) {
inputName = (EditText)findViewById(R.id.name);
Intent nextscreen = new Intent(this, newscreen.class);
//Sending value to the next activity
nextscreen.putExtra("name",inputName.getText().toString());
startActivity(nextscreen);
}
}
를 통해 데이터를 받아 첫 번째 활동에 대한 코드입니다 그리고 여기에 ID가 "btnclick"입니다 버튼 클릭시 활성화되어야 다음 활동에 대한 코드입니다 :
package kk.screen;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class newscreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newscreen);
TextView txtName = (TextView) findViewById(R.id.txtName);
Intent i=getIntent();
//Receiving the data
String name = i.getStringExtra("name");
//Display received data
txtName.setText(name);
}
}
버튼을 클릭하면 앱이 충돌하고 홈 화면으로 돌아갑니다.
무엇이 문제 일 수 있습니까 ?? OnClickListener()를 사용해야합니까 ?? (내 접근 방식과 튜토리얼의 접근 방식 사이에 큰 차이가있는 것 같다.)
로그 캣 전자를 게시하시기 바랍니다 "모든 활동은 매니페스트 파일의 요소로 표현해야" rrors. main.xml 게시도 도움이 될 수 있습니다. – Sam