私はアプリケーションで作業しており、EditTextをXMLファイルに取得できません。xmlファイルにEditTextを追加すると動作しません
ScrollViewを追加しても機能しませんでしたので、削除して画面全体にグループを広げましたが、修正できません。
PlayScreen.java
/**
* Created by Gavin on 8/10/2016.
*/
public class PlayScreen extends Activity {
public EditText numberOP;
private RelativeLayout layout;
private int i = 0;
private int x = 0;
private int y = 1;
private int z = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.layout_play);
numberOP = (EditText) findViewById(R.id.number_of_players);
layout = (RelativeLayout) findViewById(R.id.layout_play_id);
}
public void onEnterClickOne(View view) {
/**if(textView != null) {
layout.removeView(textView);
}
if(editText != null) {
layout.removeView(editText);
}*/
int b = 0;
if(i+y+x+z != 0) {
for (b = 0; b < i + y + x + z * 100; b++) {
System.out.println(b);
View v = findViewById(b);
if (v != null) {
layout.removeView(v);
}
}
}
i = 0;
x = 0;
y = 1;
z = 1;
if (numberOP.getText().toString().length() > 0) {
int length = Integer.parseInt(numberOP.getText().toString())*2;
for (i = 0; i < length; i++) {
if (i % 2 == 0) {
x++;
TextView textView = new TextView(PlayScreen.this);
textView.setId(x*30);
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
textView.setText(String.format("Group: %s", Integer.toString(x)));
textView.setTextSize(20);
textView.setTypeface(null,Typeface.BOLD);
layout.addView(textView);
}
EditText editText = new EditText(PlayScreen.this);
editText.setId(i+1);
editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
if(y == 1) {
editText.setHint("Partner 1");
y++;
} else if(y == 2) {
editText.setHint("Partner 2");
y--;
}
layout.addView(editText);
}
}
}
}
layout_play.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:background="#f7f7f7"
android:id="@+id/layout_play_id"
android:padding="25dp">
<TextView
android:text="@string/choose_your_partners"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="31sp"
android:layout_centerHorizontal="true"
android:id="@+id/editTextTwo" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:ems="10"
android:hint="@string/number_of_groups"
android:id="@+id/number_of_players"
android:layout_below="@+id/editTextTwo"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_1_text"
android:textSize="30sp"
android:id="@+id/playButton"
android:onClick="onEnterClickOne"
android:layout_below="@+id/number_of_players"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
あなたがScrollViewのための任意の提案を持っている場合にも、それは素晴らしいことです。ありがとう。ビューコンポーネントのような種類について
EditTextが表示されない、または何が表示されないのはどういう意味ですか? –
TextViewとEditTextは、画面上で右上に表示されるのではなく、画面全体に広がります。 –
問題を示す画像を投稿に追加しました。 –