Android – dynamically add multiple textviews to tablerow through SQL loop
•
Android
I've searched here, but it seems that I can't solve this problem. I have a Scrollview. In the Scrollview is LinearLayout. I want to read my SQL database and display similar results;
Linear Layout
ScrollView
Linear Layout
TableRow
TextView
TextView
TableRow
TextView
TextView
/Linear Layout
/ScrollView
/LinearLayout
My code is as follows:
TableRow tRow;
ContextThemeWrapper ttRow = new ContextThemeWrapper(this, R.style.coreTable);
LinearLayout LL = (LinearLayout) findViewById(R.id.linearCores);
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
if (cores.moveToFirst()) {
while (cores.isAfterLast() == false) {
Log.e("CORE LIST", cores.getString(1));
tRow = new TableRow(ttRow);
tRow.setLayoutParams(lp);
tRow.setOrientation(TableRow.VERTICAL);
tRow.setId(cores.getInt(0));
tRow.setBackgroundResource(R.drawable.shape_border);
ContextThemeWrapper newTxtA = new ContextThemeWrapper(this, R.style.coreHeaderView);
TextView tTextA = new TextView(newTxtA);
tTextA.setLayoutParams(lp);
tTextA.setText(cores.getString(1) + " (Lvl " + cores.getString(2) + ")");
tRow.addView(tTextA);
TextView tTextB = new TextView(coreChooser.this);
tTextB.setLayoutParams(lp);
tTextB.setText(cores.getString(5));
tRow.addView(tTextB);
LL.addView(tRow);
cores.moveToNext();
}
}
On my simulator, it shows the first Trow. Addview, but nothing else, but the background appears to have exceeded the screen
I'm really not sure what I did wrong here
resolvent:
The document of tablerow indicates the following:
If you just want each pair of textviews to share a common background r.drawable.shape_ Border, you can use nested LinearLayout instead of tablerow (in any case, tablerow is extended from LinearLayout)
Or, if you really want to use some specific features of tablerow, make r.id.linearcores tablelayout instead of LinearLayout
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码