- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在线程中创建一个动态表格布局(因为我有一个巨大的表格并且加载时间很长)。它似乎一直工作到第四行,但在出现错误之后。
我找不到问题出在哪里。在此 java 代码中,已简化表布局以解决问题。
我的java代码:
public class DialogActivity extends Activity implements Runnable {
private TextView tv;
private ProgressDialog pd;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.main1);
tv.setText("Press any key to start calculation");
pd = ProgressDialog.show(this, "Working..", "Calculating", true,false);
Thread thread = new Thread(this);
thread.start();
}
public void run() {
TableLayout table = (TableLayout)findViewById(R.id.tdyn);
TableRow row=null;
TextView label = null;
int size=10;
for (int i = 0; i < size; i++)
{
row = new TableRow(this);
//row.setId(100+i);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
for (int j = 0; j < size; j++)
{
Log.i("Test",Integer.toString(i) + "-" + Integer.toString(j));
label = new TextView(this);
label.setText(Integer.toString(i) + "-" + Integer.toString(j) + " ");
label.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
label.setGravity(Gravity.CENTER_VERTICAL);
row.addView(label);
}
if(i%2==0)
row.setBackgroundColor(0xff222222);
else
row.setBackgroundColor(0xff000000);
table.addView(row);
}
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();
tv.setText("ok");
}
};
}
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/main1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test"
/>
<TableLayout android:layout_height="wrap_content" android:id="@+id/tdyn" android:background="#F87907" android:layout_width="fill_parent">
<TableRow>
<TextView android:id="@+id/info"
android:text="test11"
android:textColor="#000000"
android:layout_gravity="center_horizontal" />
<TextView android:id="@+id/info"
android:text="test12"
android:textColor="#000000"
android:layout_gravity="center_horizontal" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
谢谢你的帮助
Edit : You can find the the logcat :
09-12 12:06:57.973: INFO/Test(215): 8-1
09-12 12:06:57.973: INFO/Test(215): 8-2
09-12 12:06:57.983: INFO/Test(215): 8-3
09-12 12:06:57.993: INFO/Test(215): 8-4
09-12 12:06:58.003: INFO/Test(215): 8-5
09-12 12:06:58.003: INFO/Test(215): 8-6
09-12 12:06:58.012: INFO/Test(215): 8-7
09-12 12:06:58.024: INFO/Test(215): 8-8
09-12 12:06:58.024: INFO/Test(215): 8-9
09-12 12:06:58.044: WARN/dalvikvm(215): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
09-12 12:06:58.044: ERROR/AndroidRuntime(215): Uncaught handler: thread Thread-8 exiting due to uncaught exception
09-12 12:06:58.073: ERROR/AndroidRuntime(215): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.ViewRoot.checkThread(ViewRoot.java:2683)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.ViewRoot.requestLayout(ViewRoot.java:557)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.View.requestLayout(View.java:7918)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.View.requestLayout(View.java:7918)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.View.requestLayout(View.java:7918)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.View.requestLayout(View.java:7918)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.View.requestLayout(View.java:7918)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.View.requestLayout(View.java:7918)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.widget.TableLayout.requestLayout(TableLayout.java:223)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.ViewGroup.addView(ViewGroup.java:1754)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.widget.TableLayout.addView(TableLayout.java:418)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.ViewGroup.addView(ViewGroup.java:1713)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.widget.TableLayout.addView(TableLayout.java:400)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.view.ViewGroup.addView(ViewGroup.java:1693)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at android.widget.TableLayout.addView(TableLayout.java:391)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at com.sil.DialogActivity.run(DialogActivity.java:65)
09-12 12:06:58.073: ERROR/AndroidRuntime(215): at java.lang.Thread.run(Thread.java:1096)
09-12 12:06:58.102: INFO/Process(52): Sending signal. PID: 215 SIG: 3
09-12 12:06:58.102: INFO/dalvikvm(215): threadid=7: reacting to signal 3
09-12 12:06:58.102: ERROR/dalvikvm(215): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
09-12 12:06:58.464: INFO/ARMAssembler(52): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x546c90:0x546d4c] in 655949 ns
09-12 12:06:58.663: INFO/ActivityManager(52): Displayed activity com.sil/.DialogActivity: 4121 ms (total 4121 ms)
最佳答案
请尝试下面编写的代码。您当前的代码有一些修改。所有的东西都是通过代码动态生成的。
public class DialogActivity extends Activity {
private LinearLayout mainLayout;
private LinearLayout innerLayout;
private TextView tv;
private ProgressDialog pd;
private int size = 10;
private int increment = 0;
private TableLayout table;
private Context context;
private TableRow row;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
context = this;
mainLayout = new LinearLayout(context);
mainLayout.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mainLayout.setOrientation(LinearLayout.VERTICAL);
innerLayout = new LinearLayout(context);
innerLayout.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
innerLayout.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(context);
tv.setText("Press any key to start calculation");
table = new TableLayout(context);
table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
table.setBackgroundColor(Color.parseColor("#F87907"));
pd = new ProgressDialog(context);
pd.setMessage("Calculating");
pd.setTitle("Working....");
pd.setIndeterminate(true);
pd.setMax(size);
pd.show();
ThreadRender thread = new ThreadRender();
thread.start();
}
private class ThreadRender extends Thread {
public void run() {
Looper.prepare();
TextView label = null;
for (int i = 0; i < size; i++) {
row = new TableRow(context);
// row.setId(100+i);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
for (int j = 0; j < size; j++) {
Log.i("Test",
Integer.toString(i) + "-" + Integer.toString(j));
label = new TextView(context);
label.setText(Integer.toString(i) + "-"
+ Integer.toString(j) + " ");
label.setLayoutParams(new TableRow.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
label.setGravity(Gravity.CENTER_VERTICAL);
row.addView(label);
}
if (i % 2 == 0) {
row.setBackgroundColor(0xff222222);
} else {
row.setBackgroundColor(0xff000000);
}
table.addView(row);
increment++;
handler.sendEmptyMessage(101);
}
handler.sendEmptyMessage(102);
}
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 102:
innerLayout.addView(tv);
innerLayout.addView(table);
mainLayout.addView(innerLayout);
setContentView(mainLayout);
pd.dismiss();
tv.setText("ok");
break;
case 101:
Log.i("Test", " " + increment);
pd.setProgress(increment);
break;
}
}
};
}
关于android - 在线程中创建动态 tableLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7386164/
我有2000条记录,我想在tablelayout中显示产品列表。第一次加载需要显示50条记录,其余记录需要分页显示。 在 onCreate() 中我完成了表格布局:它的动态表格内容 tl = (
已编辑:我自己找到了解决方案。谢谢! 我想为 Android 应用程序创建以下屏幕: 现在我有这个: 使用此代码:
我正在尝试做我的第一个复杂的 GUI,但现在我无法解决这个问题。 前两行的第一列只需要包含标签,而前两行的第二列必须占据剩余空间。 在此快照中,我注意到的问题是第一列比我想要的要大。 这是实现该布局的
当仅添加第一行时,一切顺利,但在添加第二行后,它失败了。 pupils=db.getAllPupilsPupil(); events=db.getAllEvents(); TableLayout ta
我想制作一款类似 Jeopardy 的游戏,为了实现这一目标,我决定使用 TableLayout 布局。这就是我的代码现在的样子: import javax.swing.JButton; import
我在 ListView 中使用 TableLayout。我提供的数据本质上是表格形式的,TableLayout 似乎是确保列按需要排列的好方法。这种方法在大多数情况下都很有效 - 见下文。 所需 Vi
我想发布一张图片来描述这个问题,但显然我在 stackoverflow 方面的声誉还不够,所以我将尝试描述我想要完成的事情。 我有一个包含 5 列的 TableLayout。它们由公司名称、职位编号、
我想实现一个带分页的 TableLayout,在第 1 页显示 10 条记录,然后在第 2 页显示下 10 条记录,依此类推...我正在使用 Table Layout但我没有得到所需的结果。使用本教程
我正在构建一个吉他应用程序。屏幕右侧是指板,左侧是几个按钮。 我用一个充满按钮的表格布局构建了吉他琴颈。没什么特别的。这工作得很好。不过我也想支持平板电脑。 吉他琴颈的宽度必须与每个设备保持一致,并且
在我现有的代码中,我有三个按钮,它们在同一行上水平对齐,但是,我希望这些按钮出现在不同的行上。 现有布局... [-----] [-----] [------] 追求布局... [------] [-
我的表格布局有点问题。 我有两列 专栏 1 |第 2 列 column1 内容是静态的,表示一个属性,例如“位置”,“产品”。第二列使用适配器填充。 我的问题是 TextView 打断了 column
我的目标是从数据库中获取数据,然后在我的应用程序中将其显示为表格。 这是我的代码: public void updateLastExpenses(){ Cursor c = Expense.
我一直在尝试基于 Google Play 商店中名为 Timetable 的应用程序创建一个应用程序。在过去的几天里,我一直在努力解决一个看似简单的问题。基本上,我使用 TableLayout 创建了
我正在努力寻找一种在 TableLayout 中添加和删除可点击按钮的好方法。 所以我目前有一个包含整数和对象的 HashMap。它也随着用户的需要而更新。当用户按下“添加项目”按钮时,我希望它完成向
请参阅下面的屏幕截图,了解平板电脑和手机上的不同结果。 Activity .xml
我有一个包含三列的 TableLayout,代表一个带有 的表单 必填符号 |标签 |输入框。 我希望输入字段填充屏幕右侧标签的剩余宽度。到目前为止,我找到的唯一解决方案是这个
我有一个类,其内容设置为具有几个按钮和一个 TableLayout 的布局。 制作 TableLayout 的真正工作是在一个单独的静态助手类中,它有一个返回所需表格的方法。 但是,表格没有显示。我错
我想在线程中创建一个动态表格布局(因为我有一个巨大的表格并且加载时间很长)。它似乎一直工作到第四行,但在出现错误之后。 我找不到问题出在哪里。在此 java 代码中,已简化表布局以解决问题。 我的ja
大家早上好 我在学习 Android 的道路上还面临着另一个问题。我用 CSV 文件的内容制作了一个动态 TableLayout。我需要当我点击/触摸表格中的一行时,颜色应该改变,然后点击一个按钮获取
是否可以并排显示两个 TableLayout(在 RelativeLayout 中)以使两个表格具有相同的宽度?我只是不知道该怎么做。我已经尝试过将 android:stretchColumns="*
我是一名优秀的程序员,十分优秀!