Androidで実行時に編集テキストを動的に配置するにはどうすればよいですか?
followigは私のコードです:
public class ABCActivity extends Activity {
EditText ed;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed = new EditText(ABCActivity.this);
ed.setEnabled(false);
layout =new LinearLayout(this);
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, 1.0f);
layout.setLayoutParams(params);
btn = new Button(this);
btn.setLayoutParams(params);
btn.setText("Change");
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) ed.getLayoutParams();
params2.leftMargin = 10;
params2.topMargin = 10;
ed.setLayoutParams(params2);
layout.addView(btn);
layout.addView(ed);
}
}
力を に近づける:
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) ed.getLayoutParams();
error: Null pointer Exception 相対レイアウトを使用してみました ..... しかし動作しません