我的这个程序的功能就是点一下一个按钮,添加两个tablerow,一行文本框,一行按钮,可出来按钮总是跟着文本框的长度变化~~555,哭死了
比如刚开始是这样:输入字母后就成这样了
请问这是为什么啊?
public void addtablerow( ){
//自动完成文本框
final String i="1";
ArrayAdapter<String> ausuadpter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,this.asus);
AutoCompleteTextView auto1=new AutoCompleteTextView(this);
auto1.setAdapter(ausuadpter);
auto1.setCompletionHint("请选择华硕主板型号");
//数字
final EditText text=new EditText(this);
text.setText(i);
text.setRawInputType(InputType.TYPE_CLASS_NUMBER);
//按钮+
Button button1=new Button(this);
button1.setText("+");
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String a;
a=text.getText().toString();
int num =Integer.parseInt(a);//将字符串转换成int
num++;
String c = Integer.toString(num);
text.setText(c);
}
});
//按钮-
Button button2=new Button(this);
button2.setText("-");
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String a;
a=text.getText().toString();
int num =Integer.parseInt(a);//将字符串转换成int
num--;
String c = Integer.toString(num);
text.setText(c);
}
});
//添加到tablerow
TableRow tablerow1=new TableRow(this);
TableRow tablerow2=new TableRow(this);
tablerow1.addView(auto1);
tablerow2.addView(button1);
tablerow2.addView(text);
tablerow2.addView(button2);
TableLayout asus=(TableLayout)findViewById(R.id.tablelayout1);
//添加到布局管理器
asus.addView(tablerow1);
asus.addView(tablerow2);
}android求助
比如刚开始是这样:输入字母后就成这样了
请问这是为什么啊?
public void addtablerow( ){
//自动完成文本框
final String i="1";
ArrayAdapter<String> ausuadpter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,this.asus);
AutoCompleteTextView auto1=new AutoCompleteTextView(this);
auto1.setAdapter(ausuadpter);
auto1.setCompletionHint("请选择华硕主板型号");
//数字
final EditText text=new EditText(this);
text.setText(i);
text.setRawInputType(InputType.TYPE_CLASS_NUMBER);
//按钮+
Button button1=new Button(this);
button1.setText("+");
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String a;
a=text.getText().toString();
int num =Integer.parseInt(a);//将字符串转换成int
num++;
String c = Integer.toString(num);
text.setText(c);
}
});
//按钮-
Button button2=new Button(this);
button2.setText("-");
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String a;
a=text.getText().toString();
int num =Integer.parseInt(a);//将字符串转换成int
num--;
String c = Integer.toString(num);
text.setText(c);
}
});
//添加到tablerow
TableRow tablerow1=new TableRow(this);
TableRow tablerow2=new TableRow(this);
tablerow1.addView(auto1);
tablerow2.addView(button1);
tablerow2.addView(text);
tablerow2.addView(button2);
TableLayout asus=(TableLayout)findViewById(R.id.tablelayout1);
//添加到布局管理器
asus.addView(tablerow1);
asus.addView(tablerow2);
}android求助
解决方案 »
- 关于安卓中context的问题。
- android仿酷狗界面设计问题,求解答。。。
- (Android)求助!界面的布局
- 如何把bootanimation.zip 打包到android系统镜像?
- Income Tax ID和VAT ID怎么填啊?
- android开发中Caused by: java.lang.NullPointerException
- Andorid 中的代码哪一个类是实现像JS的Confirm,.NET的MessageBox的? 谢谢
- 神了,webview下一个界面的触摸响应可以传到下一个界面吗?
- 为什么我的网站在电脑上很快,手机上就连接超时了呢?
- 如何锁屏状态下,也能让光线传感器打开
- mx2 alertdialog 挡住了smartbar,怎么办?
- SurfaceView与滑动页面冲突问题,求解决
tableRow类似单元格的形式....上面那个变了下面也要跟着变
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="+" />
<TextView
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="+" />
</TableRow>
这样就不会跟着上面那个变了或者你可以改成其它布局方式.不用tableRow