Java 在点击按钮的android上添加文本视图?
我有一个按钮,可以将用户信息插入数据库。 除此之外,我希望它能在下面的列表中显示用户输入的详细信息Java 在点击按钮的android上添加文本视图?,java,android,Java,Android,我有一个按钮,可以将用户信息插入数据库。 除此之外,我希望它能在下面的列表中显示用户输入的详细信息 @Override public void onClick(View v) { insertuser(); LinearLayout createworkout = (LinearLayout)findViewById(R.id.createworkout); TextView x = new TextView(getApplicationContext()); x
@Override
public void onClick(View v) {
insertuser();
LinearLayout createworkout = (LinearLayout)findViewById(R.id.createworkout);
TextView x = new TextView(getApplicationContext());
x.setText(editTextExercise.toString());
createworkout.addView(x);
}
这就是我目前所拥有的。单击按钮时,信息被插入,但我看不到可见的文本视图。也没有抛出错误,我不知道我做错了什么
感谢您的帮助
谢谢是否设置了LinearLayout方向属性 尝试添加:
android:orientation="vertical"
或:
尝试将其更改为
@Override
public void onClick(View v) {
insertuser();
LinearLayout createworkout = (LinearLayout)findViewById(R.id.createworkout);
TextView x = new TextView(YourActivity.this);
x.setText(editTextExercise.toString());
LayoutParams lp = new LayoutParams ( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
createworkout.addView(x,lp);
}
x、 setTextColor(颜色为黑色);也许会有帮助。可能有两件事。。。首先将
getApplicationContext
更改为您的活动。这将。。二,。检查您的布局(createworkout
)没有固定的高度和宽度。。可能未显示,但已添加。布局设置为与父项匹配。它在xmlSo中设置为垂直。因此,可能将LayoutParams添加到TextView?已添加但仍不可见尝试此解决方案,不幸的是,它不适用于我。没有抛出错误,但没有可见的文本视图。请尝试将其设置为<代码>x.setText(“这是文本视图”)代码>我认为您没有在textview上设置文本。。
@Override
public void onClick(View v) {
insertuser();
LinearLayout createworkout = (LinearLayout)findViewById(R.id.createworkout);
TextView x = new TextView(YourActivity.this);
x.setText(editTextExercise.toString());
LayoutParams lp = new LayoutParams ( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
createworkout.addView(x,lp);
}