我正在编写以下代码..但有些部分工作,有些不工作,我不知道为什么..
这些工作正常
ScrollView deviceList = (ScrollView) findViewById(R.id.deviceManager);
deviceList.setBackgroundColor(Color.CYAN);
TableLayout deviceTable = new TableLayout(getApplicationContext());
deviceTable.setId(951357);
TableRow tr = new TableRow(getApplicationContext());
LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(layout);
TextView tv = new TextView(getApplicationContext());
tv.setText("Searching");
tv.setVisibility(1);
tr.addView(tv);
deviceTable.addView(tr);
deviceList.addView(deviceTable);
Thread.sleep(1000)
deviceTable.removeAllViews();
LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
TableRow tr = new TableRow(getApplicationContext());
TextView tv = new TextView(getApplicationContext());
tv.setLayoutParams(layout);
tr.setLayoutParams(layout);
tv.setText("No more devices");
if(rowCounter%2==0)
{
System.out.println("rowCounter%2==0");
tv.setTextColor(Color.WHITE);
tr.setBackgroundColor(Color.DKGRAY);
}
else
{
System.out.println("rowCounter%2==1");
tv.setTextColor(Color.WHITE);
tr.setBackgroundColor(Color.GRAY);
}
不工作
tv.setVisibility(1);
tv.setEnabled(true);
tr.addView(tv);
tr.setVisibility(1);
deviceTable.addView(tr);
再次工作
System.out.println(tv+" "+tr+" "+deviceTable+" "+tv.getText());
deviceTable.setBackgroundColor(Color.BLACK);
System.out.println("No more devices");
编辑:
tv.setVisibility(View.VISIBLE);
tv.setEnabled(true);
tr.addView(tv);
tr.setVisibility(View.VISIBLE);
deviceTable.addView(tr);
System.out.println(tv+" "+tr+" "+deviceTable+" "+tv.getText());
deviceTable.setBackgroundColor(Color.BLACK);
System.out.println("No more devices");