public class TestForm extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testpage);
final EditText txtShow = (EditText)this.findViewById(id.testEditText);
Intent intenter = getIntent();
txtShow.setText(intenter.getStringExtra("res").toString());
Button btn1=(Button)this.findViewById(id.testBtnOk);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CreateView();
}
});
}
public void CreateView()
{
TableLayout tl = (TableLayout)findViewById(R.id.testTblay);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
tl.addView(tr);
/* Create a TextView to be the row-content. */
TextView txt1 = new TextView(this);
txt1.setText("我");
txt1.setId(0);
txt1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Add TextView to row. */
tr.addView(txt1);
tl.setShrinkAllColumns(true);
}
}XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <EditText
android:id="@+id/testEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <requestFocus />
</EditText>
<Button
android:id="@+id/testBtnOk"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:text="新增"
android:orientation="vertical" /> <TableLayout
android:id="@+id/testTblay"
android:layout_width="wrap_content"
android:layout_height="420dp"
android:shrinkColumns="0" >
</TableLayout>
</LinearLayout>
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testpage);
final EditText txtShow = (EditText)this.findViewById(id.testEditText);
Intent intenter = getIntent();
txtShow.setText(intenter.getStringExtra("res").toString());
Button btn1=(Button)this.findViewById(id.testBtnOk);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CreateView();
}
});
}
public void CreateView()
{
TableLayout tl = (TableLayout)findViewById(R.id.testTblay);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
tl.addView(tr);
/* Create a TextView to be the row-content. */
TextView txt1 = new TextView(this);
txt1.setText("我");
txt1.setId(0);
txt1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Add TextView to row. */
tr.addView(txt1);
tl.setShrinkAllColumns(true);
}
}XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <EditText
android:id="@+id/testEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <requestFocus />
</EditText>
<Button
android:id="@+id/testBtnOk"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:text="新增"
android:orientation="vertical" /> <TableLayout
android:id="@+id/testTblay"
android:layout_width="wrap_content"
android:layout_height="420dp"
android:shrinkColumns="0" >
</TableLayout>
</LinearLayout>
解决方案 »
- android编程中怎么调用设备上已安装的应用程序
- jdk1.7的@override蛋疼问题
- 收藏 Android 使用proguard导出项目时 报错
- 为什么找不到getAllMessagesFromIcc
- android 开发 网络IP 转发的问题
- android 获取 网络 下载地址
- android 横屏后如何确保数据不丢失。
- 一个简单的layout问题,两行两列,其中一列合并的layout问题
- 推荐:Android快速开发软件--谷歌推Google App Inventor工具 力拼iPhone OS
- 大家平常开发用到哪些第三方包
- TabActivity问题
- 修改了frameworks/base/core/res/res/drawable下的xml文件,但是不知道如何快速编译
txtShow.setText(intenter.getStringExtra("res").toString());这里有问题,去掉,代码是正确的