2011-08-03 5 views
0

사용자 데이터를 가져 오는 데 사용하려는 간단한 양식 페이지가 있습니다. 여기에는 세 개의 필드가 있습니다.Android에서 양식 데이터 읽기 및 표시

1.Name 필드 (텍스트 편집 형)

2.Radio 버튼 (라디오 버튼에서 라디오 그룹) "남성 또는 여성"

3.Drop 다운 메뉴 (회 전자)를 "나라를 선택"

main.xml 
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="1px"> 
<TextView 
android:id="@+id/tasks_title" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/tasks"/> 
<ListView 
android:id="@id/android:list" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_below="@id/tasks_title" 
android:layout_above="@+id/add_button"/> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@id/android:empty" 
android:text="@string/no_tasks" 
android:gravity="center_vertical|center_horizontal" 
android:layout_below="@id/tasks_title" 
android:layout_above="@+id/add_button"/> 
<Button 
android:id="@id/add_button" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/add_task" 
android:layout_alignParentBottom="true" 
/> 
</RelativeLayout> 

the program as viewed while running the emulator

제작 한 또 다른 활동은

을 FormActivity.java라고
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.RadioGroup; 
import android.widget.Spinner; 

public class FormActivity extends Activity { 
private Button submitbutton; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    submitbutton=(Button)findViewById(R.id.submit_button); 
    submitbutton.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
    Intent intent = new Intent(FormActivity.this, DisplayActivity.class); 
    startActivity(intent); 
    } 
}); 
    /**Implements DropDownMenu (spinner) by pushing items into an array an displaying them**/ 
      Spinner spinner = (Spinner)findViewById(R.id.spinner); 
      ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
      R.array.countries_array, android.R.layout.simple_spinner_item); 
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
      spinner.setAdapter(adapter); 
     } 

} 

xml 파일의 데이터를 다른 페이지에 표시하는 방법은 무엇입니까? 제가 지금 안드로이드를 배우면서 지침을주세요.

감사가 새로운 의도에서 좋은 일

답변

1
Intent intent = new Intent(FormActivity.this, DisplayActivity.class); 
EditText inputName = (EditText) findViewById(R.id.inputText); 
String name = inputName.getText().toString(); 
intent.putExtra("name" , name); 
startActivity(intent); 

당신이 싹둑를 사용

Bundle extras = getIntent().getExtras(); 
String name = extras.getString("name"); 
1

당신은 의도에 엑스트라로 데이터를 전달할 수 있지만 당신은 또한 사용자 정의 클래스를 가질 수 있습니다 응용 프로그램에서 상속 된, 그것을 보이게하고 필요한 값으로 채 웁니다. 이는 응용 프로그램 전체에서 동일한 도메인 (동일한 사용자, 초기화 값 등) 또는 '전역'기능 (읽기 - 쓰기 로컬 데이터, 모든 자원 테스트 등)이있는 경우에 유용합니다.

응용 프로그램 : 이름을 Manifest에 추가 한 다음 사용자 응용 프로그램 클래스에 사용자 지정 코드를 추가 할 수 있습니다.