2016-05-04 13 views
-2

私は相対レイアウトとtextviewsとedittextの 'n'個の番号を持っています。私は整列をしたいダイナミックに作成されたテキストビューとアンドロイドでテキストを編集する

TextView EditText 
     Button 
    TextView EditText 
     Button 
    TextView EditText 
     Button 
    TextView EditText 
     Button 
    .......... 

私はレイアウトパラメータを使用しようとしましたが、私は奇妙な結果を得ています。ここ は私のコードは、私がこのようなlayout_paramsを適用しているが、それは助けていない、テキスト編集..

final EditText[] editTextarray = new EditText[41]; 
    for (int i = 0; i < 41; i++) { 
     // create a new textview 
     final EditText editText = new EditText(this); 
     RelativeLayout.LayoutParams paramsB = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     editText.setText("edit"); 
     editText.setCursorVisible(true); 
     relativeLayout.addView(editText, paramsB); 
     editTextarray[i] = editText; 

    } 

については

RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.linearlayoutid); 
    final TextView[] myTextViews = new TextView[41]; 
    for (int i = 0; i < 41; i++) { 
     // create a new textview 
     rowTextView = new TextView(this); 
     RelativeLayout.LayoutParams paramsA = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     paramsA.addRule(RelativeLayout.RIGHT_OF, rowTextView.getId()); 
     rowTextView.setId(i); 
     // add the textview to the layout 
     relativeLayout.addView(rowTextView, paramsA); 
     myTextViews[i] = rowTextView; 

    } 

です。どんな助けも素晴らしいだろう!ありがとう

+0

なぜここで線形レイアウトを使用しませんでしたか? –

+0

paramsを使わずに線形レイアウトを使用しますか?その動的に生成されます。線形レイアウトはどのようにすることができますか?それは約100の編集テキストを動的に生成します@SohailZahid – Anusha

+0

あなたが相対的なレイアウトプロパティを使用していない場合、単純に線形レイアウトをオリエンテーションで使います。 –

答えて

0

私はあなたがカスタムレイアウトを使用し、プログラムでそれを膨らませることをお勧めします。

TextView,EditTextButtonのレイアウトを作成し、それを膨張させます。

View v=LayoutInflater.from(this).inflate(R.layout.customLayout,null); 

v変数がTextViewEditTextButtonを参照するために使用します。

あなたcustomLayout.xmlはこのようなものになることができます。

<LinearLayout android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

方向垂直を持つあなたのXMLでLinearLayoutを取り、別のビューを作成するために、そのレイアウトでこのビューを追加します。

for (int i = 0; i < 20; i++) { 
    View v = inflater.inflate(R.layout.customLayout, null); 

    ll.addView(v); 
} 
+0

自分のコードを変更して解決策として提供できますか? @Ravi Rupareliya – Anusha

+0

申し訳ありませんが、あなたにそれについてのヒントを与えることができます、あなた全体のコードを与えることはできません。人々がこれ以上downvote場合でも私はそれを受け入れるだろう。 –

+0

LinearLayout lv =(LinearLayout)findViewById(R.id.linearlayoutid); 。 idを使ってlinearlayoutにアクセスする必要がありますか?あなたのコードのL1は参照権ですか? – Anusha

0

layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:id="@+id/ll" 
     > 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="textview" 
      /> 
     <EditText 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Edittex" 
      /> 

    </LinearLayout> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ll" 
     android:layout_centerHorizontal="true" 
     android:text="button" 
     /> 

</RelativeLayout> 

は、実行時にこのレイアウトを追加レイアウトを追加します。あなたの場合

View view; 
    LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    for (int i = 0; i < 40; i++) { 

    view= inflater.inflate(R.layout.layout, null); 
    linearLayout.addView(view); 
    } 
+0

ダイナミック値をテキストビューに渡す方法を教えてください。 @Pradeep Gupta – Anusha

+0

これをforループに追加するTextView tvBuy =(TextView)view.findViewById(R.id.textview); tvBuy .setText( "your value"); –

+0

(LayoutInflator)式の表示エラーが予想されます@Pradeep Gupta – Anusha

0

anushaにはまだのLinearLayout

でこれを試してみてくださいデザインはidentですあなたはlistviewのベスト・アプローチを使うべきです。

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearlayoutid); 
     final TextView[] myTextViews = new TextView[41]; 
     final EditText[] editTextarray = new EditText[41]; 
     for (int i = 0; i < 41; i++) { 
      // create a new textview 
      rowTextView = new TextView(this); 
      myTextViews[i] = rowTextView; 
      linearLayout.addView(myTextViews[i]); 

      final EditText editText = new EditText(this); 
      editText.setText("edit"); 
      editText.setCursorVisible(true); 
      editTextarray[i] = editText; 
      linearLayout.addView(editTextarray[i]); 

     } 
0

は、私はあなたがこの要件のためにリストビューを実装することをお勧め - あなたの現在のアプローチパー

をあなたは終わらアップしますあなたのボタンのそれぞれに対して複数のonClicklistenersを設定する - そのボタンは入力のデータを選択するために起こっている場合TextViewの/のEditTextに関連付けられている - すべてのあなたが

PSを区別しますが、1 onClickListenerを発射することができます項目のonclickの - あなたは多くの配列の呼び出しやもの

リストビューを書くことになります:ボタンがあること繰り返すように悪いデザイン低いtextview/edittextボタンが同じ/同様の機能を実行すると期待されている場合save - テキストビューのリストビュー/ edittext - ツールバー上またはフォームの下の共通のボタンアクション。

関連する問題