2013-02-01 4 views
0

질문은 4 개의 edittext 필드 (숫자)와 결과가 2 개의 열로 표시되는 테이블 레이아웃입니다. 테이블 레이아웃의 값은 모든 편집 텍스트 값이 사용되는 공식으로 계산됩니다. edittext 필드에 값을 입력 할 때 동적으로 테이블에서 응답을 업데이트하고 싶습니다. 가능한가? 그렇다면 샘플 코드를 사용하여 조명을 켜십시오.동적으로 테이블 안드로이드의 값을 업데이트하십시오.

그리고 다른 활동을하고 있습니다.

편집 텍스트 코드 화면

al_e.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      // TODO Auto-generated method stub 
      if((al<15)|(al>50)|al_e.getText().toString().length()==0){ 
       invalid=1; 
       //al_e.setText(null); 
       Toast.makeText(getApplicationContext(),"Please enter a valid input\nRange [15mm,50mm]", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 

스크린 샷.

enter image description here

은 테이블의 레이아웃 tabhost의 setContent로서 설정된다.


mTabHost=(TabHost) findViewById(android.R.id.tabhost); 
    mTabHost.setup(getLocalActivityManager()); 
    addTab("SRK/T", TAG_1, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(Second.this, Srkt_x.class)); 
    addTab("SRK II", TAG_2, createTabDrawable(R.drawable.ic_tab_eye_unselected),new Intent(Second.this, Srk2_x.class)); 
    addTab("BINKHORST", TAG_3, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(Second.this, Binkhorst_x.class)); 
    addTab("HOLLADAY", TAG_4, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent(Second.this, Holladay_x.class)); 

따 등 tabhost tabhost 활성

private void addTab(String label, String tag, Drawable drawable, Intent intent) { 
    TabHost.TabSpec spec = mTabHost.newTabSpec(tag); 
    spec.setIndicator(createTabIndicator(label, drawable)); 
    spec.setContent(intent); 
    intent.putExtra("AL", al); 
    intent.putExtra("K1", k1); 
    intent.putExtra("K2", k2); 
    intent.putExtra("ALC", al_const); 
    intent.putExtra("DR", dr); 
    intent.putExtra("INVALID", invalid); 
    mTabHost.addTab(spec); 
} 

의 구현을 위해 정의 addtab 방법 블레 트 활동은 tabhost의 내용으로 설정 한 srkt_x, srkt_2, holladay_x, binkhorst_x 활동입니다.

사실 저는 edittext 필드를 탭에 구현했으며 탭 내용을 테이블 레이아웃으로 설정했습니다. 그래서 언제 그리고 내가 edittext 필드를 업데이 트하려면 edittext 바로 아래에있는 테이블 레이아웃 필드를 원할 때.

PS : 나쁜 이미지 편집

답변

1

에 대한 용서는 당신이 사용자에 의해 업데이트됩니다 같은 내용을 얻을 수 있도록 editext에 addTextChangedListener 방법을 사용할 수 있습니다. EDITTEXT 입력으로 텍스트 뷰를 업데이트 할 문서를 here

샘플 코드를 참조하십시오

레이아웃 파일 :

<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" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="@string/hello_world" /> 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:ems="10" > 

    <requestFocus /> 
</EditText> 

활동 :

public class MainActivity extends Activity { 

private TextView textView; 
private EditText editText; 

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

    editText= (EditText)findViewById(R.id.editText1); 
    textView= (TextView) findViewById(R.id.textView); 
    editText.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      textView.setText(s); //use the charsequence s which is the current user input 

     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      // TODO Auto-generated method stub 

     } 
    }); 
} 

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

}

EDIT 테이블이 다른 활동에 있습니까 ?? 그리고 당신은 당신의 editText listener를 사용할 때 심지어 팽창하지 않는 테이블을 업데이트하려고합니까 ?? 나는 당신이 더 많은 것을 설명하고 여기에 모든 코드를 게시해야한다고 생각합니다.

EDIT 동일한 화면에서 두 가지 활동을 솔직히하는 경우는 거의 없습니다. 이제는 액티비티처럼 동작하는 프레젠테이션을 사용하여 동일한 화면에 살도록 할 수 있습니다. getActivity 메소드를 사용하여 다양한 방법으로 쉽게 서로 통신 할 수 있습니다.

+0

나는 그것을했다. 테이블조차도 업데이트되지 않습니다. 코드 샘플을 제공해 주시겠습니까 – human

+0

먼저 코드를 공유해야한다고 생각합니다. – psykhi

+0

텍스트 뷰가 다른 활동에 있다면 어떻게해야합니까? – human