Soru & Cevap

+ butonu ile TextField ekleme ...

06.11.2013 - 12:55

Ben + butonu ile yeni bir TextField eklemek istiyorum bunu nasıl yapabilirim şimdiden teşekkürler.

9 Görüntülenme

3 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-399-1379511904.jpg
halil
06.11.2013 - 01:23

bu konuda internette bulduğum bu kod belki sana yardımcı olur.

[code]

private LinearLayout mLayout;
private EditText mEditText;
private Button mButton;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mLayout = (LinearLayout) findViewById(R.id.linearLayout);
    mEditText = (EditText) findViewById(R.id.editText);
    mButton = (Button) findViewById(R.id.button);
    mButton.setOnClickListener(onClick());
    TextView textView = new TextView(this);
    textView.setText("New text");
}

private OnClickListener onClick() {
    return new OnClickListener() {

        @Override
        public void onClick(View v) {
            mLayout.addView(createNewTextView(mEditText.getText().toString()));
        }
    };
}

private TextView createNewTextView(String text) {
    final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    final TextView textView = new TextView(this);
    textView.setLayoutParams(lparams);
    textView.setText("New text: " + text);
    return textView;
}[/code]

aynı şekilde xml dosyasıda 

[code]<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout">
 <EditText 
    android:id="@+id/editText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
 />
<Button 
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add+"
/>

[/code]

picture-830-1447858140.jpg
onur
06.11.2013 - 01:19

TextView yeniTextView = new TextView(this);

yeniTextView.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

yeniTextView.setText("deneme 1 2 3");

eklemekIstediginLayout.addView(yeniTextView);

picture-6537-1395347261.jpg
igunduz91
06.11.2013 - 02:01

Merhabalar Osman,

Eğer her butona basıldığında +1 olarak textfield artacaksa bilemem lakin. Butona basıldığında var olan bir textfield'ın görüntülenmesini istiyorsanız şöyle bir şey yapabilirsiniz.

xml dosyanızda txtSozAd id'li bir textfield vardır.

onCreate butonu içerisinde bu textfield'ı tanımlarsınız. ARdından bu textfield'ın görünebilirliğini false yaparsınız. Yani şöyle ki; txtSozAd.setVisibility(Vİew.GONE); ile bu butonunuz ekranda görünmez.
İstediğiniz butona basıldıktan sonra View.VISIBLE ile tekrardan görüntületip. setText ile istediğiniz string'i yazdırabilirsiniz..

umarım aradınız cevap budur.

kolay gelsin..