我有“表布局代码”,我想增加表列。我是开发和android表布局领域的新手... 我想增加表中的列数,因为我正在使用android表布局!
但是我还是很困惑!
这是我的xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:id="@+id/invoices_layout"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="@+id/tableInvoices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
这是我的主要活动Java文件
public class MainActivity extends AppCompatActivity {
private TableLayout mTableLayout;
ProgressDialog mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgressBar = new ProgressDialog(this);
mTableLayout = (TableLayout) findViewById(R.id.tableInvoices);
mTableLayout.setStretchAllColumns(true);
startLoadData();
}
public void startLoadData() {
mProgressBar.setCancelable(false);
mProgressBar.setMessage("Fetching Invoices..");
mProgressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressBar.show();
new LoadDataTask().execute(0);
}
public void loadData() {
int leftRowMargin=0;
int topRowMargin=0;
int rightRowMargin=0;
int bottomRowMargin = 0;
int textSize = 0, smallTextSize = 0 , mediumTextSize = 0;
textSize = (int) getResources().getDimension(R.dimen.font_size_verysmall);
smallTextSize = (int) getResources().getDimension(R.dimen.font_size_small);
mediumTextSize = (int) getResources().getDimension(R.dimen.font_size_medium);
Invoices invoices = new Invoices();
InvoiceData[] data = invoices.getInvoices();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM, yyyy");
DecimalFormat decimalFormat = new DecimalFormat("0.00");
int rows = data.length;
getSupportActionBar().setTitle("Invoices (" + String.valueOf(rows) + ")");
TextView textSpacer = null;
mTableLayout.removeAllViews();
for(int i = -1; i < rows; i ++) {
InvoiceData row = null;
if (i > -1)
row = data[i];
else {
textSpacer = new TextView(this);
textSpacer.setText("");
}
final TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv.setGravity(Gravity.LEFT);
tv.setPadding(5, 15, 0, 15);
if (i == -1) {
tv.setText("Inv.#");
tv.setBackgroundColor(Color.parseColor("#f0f0f0"));
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallTextSize);
} else {
tv.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv.setText(String.valueOf(row.invoiceNumber));
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
final TextView tv2 = new TextView(this);
if (i == -1) {
tv2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv2.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallTextSize);
} else {
tv2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.MATCH_PARENT));
tv2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
tv2.setGravity(Gravity.LEFT);
tv2.setPadding(5, 15, 0, 15);
if (i == -1) {
tv2.setText("Date");
tv2.setBackgroundColor(Color.parseColor("#f7f7f7"));
}else {
tv2.setBackgroundColor(Color.parseColor("#ffffff"));
tv2.setTextColor(Color.parseColor("#000000"));
tv2.setText(dateFormat.format(row.invoiceDate));
}
final LinearLayout layCustomer = new LinearLayout(this);
layCustomer.setOrientation(LinearLayout.VERTICAL);
layCustomer.setPadding(0, 10, 0, 10);
layCustomer.setBackgroundColor(Color.parseColor("#f8f8f8"));
final TextView tv3 = new TextView(this);
if (i == -1) {
tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
tv3.setPadding(5, 5, 0, 5);
tv3.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallTextSize);
} else {
tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
tv3.setPadding(5, 0, 0, 5);
tv3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
tv3.setGravity(Gravity.TOP);
if (i == -1) {
tv3.setText("Customer");
tv3.setBackgroundColor(Color.parseColor("#f0f0f0"));
} else {
tv3.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv3.setTextColor(Color.parseColor("#000000"));
tv3.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallTextSize);
tv3.setText(row.customerName);
}
layCustomer.addView(tv3);
if (i > -1) {
final TextView tv3b = new TextView(this);
tv3b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv3b.setGravity(Gravity.RIGHT);
tv3b.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
tv3b.setPadding(5, 1, 0, 5);
tv3b.setTextColor(Color.parseColor("#aaaaaa"));
tv3b.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv3b.setText(row.customerAddress);
layCustomer.addView(tv3b);
}
final LinearLayout layAmounts = new LinearLayout(this);
layAmounts.setOrientation(LinearLayout.VERTICAL);
layAmounts.setGravity(Gravity.RIGHT);
layAmounts.setPadding(0, 10, 0, 10);
layAmounts.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
final TextView tv4 = new TextView(this);
if (i == -1) {
tv4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
tv4.setPadding(5, 5, 1, 5);
layAmounts.setBackgroundColor(Color.parseColor("#f7f7f7"));
} else {
tv4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv4.setPadding(5, 0, 1, 5);
layAmounts.setBackgroundColor(Color.parseColor("#ffffff"));
}
tv4.setGravity(Gravity.RIGHT);
if (i == -1) {
tv4.setText("Inv.Amount");
tv4.setBackgroundColor(Color.parseColor("#f7f7f7"));
tv4.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallTextSize);
} else {
tv4.setBackgroundColor(Color.parseColor("#ffffff"));
tv4.setTextColor(Color.parseColor("#000000"));
tv4.setText(decimalFormat.format(row.invoiceAmount));
tv4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
layAmounts.addView(tv4);
if (i > -1) {
final TextView tv4b = new TextView(this);
tv4b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv4b.setGravity(Gravity.RIGHT);
tv4b.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
tv4b.setPadding(2, 2, 1, 5);
tv4b.setTextColor(Color.parseColor("#00afff"));
tv4b.setBackgroundColor(Color.parseColor("#ffffff"));
String due = "";
if (row.amountDue.compareTo(new BigDecimal(0.01)) == 1) {
due = "Due:" + decimalFormat.format(row.amountDue);
due = due.trim();
}
tv4b.setText(due);
layAmounts.addView(tv4b);
}
// add table row
final TableRow tr = new TableRow(this);
tr.setId(i + 1);
TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT);
trParams.setMargins(leftRowMargin, topRowMargin, rightRowMargin, bottomRowMargin);
tr.setPadding(0,0,0,0);
tr.setLayoutParams(trParams);
tr.addView(tv);
tr.addView(tv2);
tr.addView(layCustomer);
tr.addView(layAmounts);
if (i > -1) {
tr.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TableRow tr = (TableRow) v;
}
});
}
mTableLayout.addView(tr, trParams);
if (i > -1) {
// add separator row
final TableRow trSep = new TableRow(this);
TableLayout.LayoutParams trParamsSep = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT);
trParamsSep.setMargins(leftRowMargin, topRowMargin, rightRowMargin, bottomRowMargin);
trSep.setLayoutParams(trParamsSep);
TextView tvSep = new TextView(this);
TableRow.LayoutParams tvSepLay = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
tvSepLay.span = 4;
tvSep.setLayoutParams(tvSepLay);
tvSep.setBackgroundColor(Color.parseColor("#d9d9d9"));
tvSep.setHeight(1);
trSep.addView(tvSep);
mTableLayout.addView(trSep, trParamsSep);
}
}
}
class LoadDataTask extends AsyncTask<Integer, Integer, String> {
@Override
protected String doInBackground(Integer... params) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "Task Completed.";
}
@Override
protected void onPostExecute(String result) {
mProgressBar.hide();
loadData();
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Integer... values) {
}
}
}
这是我的模特班
public class InvoiceData {
public int id;
public int invoiceNumber;
public Date invoiceDate;
public String customerName;
public String customerAddress;
public BigDecimal invoiceAmount;
public BigDecimal amountDue;
}
这是我的帐单类别
public class Invoices {
public InvoiceData[] getInvoices() {
InvoiceData[] data = new InvoiceData[20];
for(int i = 0; i < 20; i ++) {
InvoiceData row = new InvoiceData();
row.id = (i+1);
row.invoiceNumber = row.id;
row.amountDue = BigDecimal.valueOf(20.00 * i);
row.invoiceAmount = BigDecimal.valueOf(120.00 * (i+1));
row.invoiceDate = new Date();
row.customerName = "Thomas John Beckett";
row.customerAddress = "1112, Hash Avenue, NYC";
//row.Code= "1233";
data[i] = row;
}
return data;
}
}
我想做的是我要增加表中的列数...
添加更多不显示小屏幕的列
我有8列,但只显示6
答案 0 :(得分:1)
您可以在此处查看Blackie answer,以了解如何使用xml在TableLayout中实现列数。
对于您的示例,您可以在以下示例中使用它:
<TableLayout
android:id="@+id/tableInvoices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:stretchColumns="7">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
</TableRow>
</TableLayout>
更新:
对于较小的水平尺寸,您有多种解决方案:
1-将较小的textSize用于标题和所有其他textView,并使用wrap_content
。
2-使用LinearLayout代替TableLayout,并为每列指定layout_weight。
3-使用水平ScrollView。
答案 1 :(得分:0)
您只需要像这样...更改布局文件即可。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/ordersid"
android:orientation="vertical"
tools:context="com.dynamicsolution.pakistan.TableOrdersActivity">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="@+id/tableorders"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:stretchColumns="*">
</TableLayout>
</HorizontalScrollView>
但是在水平和垂直方向上都可以滚动查看。
在Android Studio中,需要创建每个列以正确使用。
public class TableOrdersActivity extends AppCompatActivity {
public OrdersInterface datasource1;
android.widget.TableLayout t1;
String Rou = "";
String Typ = "";
String Rou1 = ""; String Typ1 = "";
List<GetSetProductsDetail> l1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_orders);
Intent ag = getIntent();
Rou= ag.getStringExtra("Rou");
Typ= ag.getStringExtra("Typ");
Rou1= ag.getStringExtra("Rou1");
Typ1= ag.getStringExtra("Typ1");
t1= (android.widget.TableLayout) findViewById(R.id.tableorders);
GetAllProduct("1",Rou1,Typ1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_client__data__show, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void GetAllProduct(String d, String Rou, String Typ){
AlertDialog alertDialog = new AlertDialog.Builder(TableOrdersActivity.this).create();
alertDialog.setTitle("Alert");
datasource1 = new OrdersInterface(this);
long rowcount = datasource1.getrowCount();
if(rowcount == 0 || rowcount < 0){
alertDialog.setMessage("No Data found go back and get from file");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent a = new Intent(TableOrdersActivity.this, SplashActivity.class);
startActivity(a);
dialog.dismiss();
}
});
alertDialog.show();
}
else {
String openresult= datasource1.openforread();
if(openresult.equals("1")){
try {
int t =0;
l1 = datasource1.getAllClients(d, Rou, Typ);
if(l1.size()==0){
alertDialog.setMessage("No data according to your Query Go Back..");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent a = new Intent(TableOrdersActivity.this, AfterSplash.class);
startActivity(a);
dialog.dismiss();
}
});
alertDialog.show();
}
for (GetSetProductsDetail cn : l1) {
if(t==0){
TableRow row= new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
TextView tv00 = new TextView(this);
tv00.setText("Code");
tv00.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv00.setTextColor(Color.BLACK);
tv00.setTextSize(13);
tv00.setGravity(Gravity.CENTER);
tv00.setPadding(10, 15, 10, 15);
tv00.setBackgroundResource(R.drawable.item);
row.addView(tv00);
TextView tv111 = new TextView(this);
tv111.setText("BarCode");
tv111.setTextColor(Color.BLACK);
tv111.setGravity(Gravity.CENTER);
tv111.setTextSize(13);
tv111.setPadding(10, 15, 10, 15);
tv111.setBackgroundResource(R.drawable.item);
row.addView(tv111);
TextView tv22 = new TextView(this);
tv22.setText("Name");
tv22.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv22.setTextColor(Color.BLACK);
tv22.setTextSize(13);
tv22.setGravity(Gravity.CENTER);
tv22.setPadding(10, 15, 10, 15);
tv22.setBackgroundResource(R.drawable.item);
row.addView(tv22);
TextView tv33 = new TextView(this);
tv33.setText("SIZE");
tv33.setTextColor(Color.BLACK);
tv33.setGravity(Gravity.CENTER);
tv33.setPadding(10, 15, 10, 15);
tv33.setBackgroundResource(R.drawable.item);
tv33.setTextSize(13);
row.addView(tv33);
TextView tv44 = new TextView(this);
tv44.setText("UNAME");
tv44.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv44.setTextColor(Color.BLACK);
tv44.setGravity(Gravity.CENTER);
tv44.setTextSize(13);
tv44.setPadding(10, 15, 10, 15);
tv44.setBackgroundResource(R.drawable.item);
row.addView(tv44);
TextView tv55 = new TextView(this);
tv55.setText("RETAIL");
tv55.setTextColor(Color.BLACK);
tv55.setTextSize(13);
tv55.setGravity(Gravity.CENTER);
tv55.setPadding(10, 15, 10, 15);
tv55.setBackgroundResource(R.drawable.item);
row.addView(tv55);
TextView tv66 = new TextView(this);
tv66.setText("WHOLESALE");
tv66.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv66.setTextSize(13);
tv66.setTextColor(Color.BLACK);
tv66.setGravity(Gravity.CENTER);
tv66.setPadding(10, 15, 10, 15);
tv66.setBackgroundResource(R.drawable.item);
row.addView(tv66);
TextView tv67 = new TextView(this);
tv67.setText("TRADE");
tv67.setTextColor(Color.BLACK);
tv67.setTextSize(13);
tv67.setGravity(Gravity.CENTER);
tv67.setPadding(10, 15, 10, 15);
tv67.setBackgroundResource(R.drawable.item);
row.addView(tv67);
TextView tv68 = new TextView(this);
tv68.setText("PERCENTAGE");
tv68.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv68.setTextColor(Color.BLACK);
tv68.setTextSize(13);
tv68.setGravity(Gravity.CENTER);
tv68.setPadding(10, 15, 10, 15);
tv68.setBackgroundResource(R.drawable.item);
row.addView(tv68);
TextView tv69 = new TextView(this);
tv69.setText("TAX");
tv69.setTextColor(Color.BLACK);
tv69.setTextSize(13);
tv69.setGravity(Gravity.CENTER);
tv69.setPadding(10, 15, 10, 15);
tv69.setBackgroundResource(R.drawable.item);
row.addView(tv69);
TextView tv70 = new TextView(this);
tv70.setText("SUBCATEGARY");
tv70.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv70.setTextColor(Color.BLACK);
tv70.setTextSize(13);
tv70.setGravity(Gravity.CENTER);
tv70.setPadding(10, 15, 10, 15);
tv70.setBackgroundResource(R.drawable.item);
row.addView(tv70);
TextView tv71 = new TextView(this);
tv71.setText("CATEGARY");
tv71.setTextColor(Color.BLACK);
tv71.setTextSize(13);
tv71.setGravity(Gravity.CENTER);
tv71.setPadding(10, 15, 10, 15);
tv71.setBackgroundResource(R.drawable.item);
row.addView(tv71);
TextView tv72 = new TextView(this);
tv72.setText("COMPANY");
tv72.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv72.setTextColor(Color.BLACK);
tv72.setTextSize(13);
tv72.setGravity(Gravity.CENTER);
tv72.setPadding(10, 15, 10, 15);
tv72.setBackgroundResource(R.drawable.item);
row.addView(tv72);
TextView tv73 = new TextView(this);
tv73.setText("TYPE");
tv73.setTextColor(Color.BLACK);
tv73.setTextSize(13);
tv73.setGravity(Gravity.CENTER);
tv73.setPadding(10, 15, 10, 15);
tv73.setBackgroundResource(R.drawable.item);
row.addView(tv73);
TextView tv74 = new TextView(this);
tv74.setText("PACKSIZE");
tv74.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv74.setTextColor(Color.BLACK);
tv74.setTextSize(13);
tv74.setGravity(Gravity.CENTER);
tv74.setPadding(10, 15, 10, 15);
tv74.setBackgroundResource(R.drawable.item);
row.addView(tv74);
TextView tv75 = new TextView(this);
tv75.setText("WEIGHT");
tv75.setTextColor(Color.BLACK);
tv75.setTextSize(13);
tv75.setGravity(Gravity.CENTER);
tv75.setPadding(10, 15, 10, 15);
tv75.setBackgroundResource(R.drawable.item);
row.addView(tv75);
TextView tv76 = new TextView(this);
tv76.setText("WEIGHTUNIT");
tv76.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv76.setTextColor(Color.BLACK);
tv76.setTextSize(13);
tv76.setGravity(Gravity.CENTER);
tv76.setPadding(10, 15, 10, 15);
tv76.setBackgroundResource(R.drawable.item);
row.addView(tv76);
TextView tv77 = new TextView(this);
tv77.setText("CURRENTSTOCK");
tv77.setTextColor(Color.BLACK);
tv77.setTextSize(13);
tv77.setGravity(Gravity.CENTER);
tv77.setPadding(10, 15, 10, 15);
tv77.setBackgroundResource(R.drawable.item);
row.addView(tv77);
t1.addView(row);
t++;
}
if (t!=0) {
String a = cn.getORDERCODE();
String f1 = cn.getBARCODE();
TableRow row1= new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row1.setLayoutParams(lp);
TextView t001= new TextView(this);
t001.setText(a.toString());
t001.setTextColor(Color.BLACK);
t001.setGravity(Gravity.CENTER);
t001.setBackgroundColor(Color.parseColor("#f8f8f8"));
t001.setBackgroundResource(R.drawable.item);
t001.setPadding(10, 15, 10, 15);
t001.setTextSize(13);
row1.addView(t001);
TextView tv1 = new TextView(this);
tv1.setText(f1.toString());
tv1.setTextColor(Color.BLACK);
tv1.setGravity(Gravity.CENTER);
tv1.setBackgroundResource(R.drawable.item);
tv1.setPadding(10, 15, 10, 15);
tv1.setTextSize(13);
row1.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setText(cn.getNAME());
tv2.setTextColor(Color.BLACK);
tv2.setGravity(Gravity.CENTER);
tv2.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv2.setBackgroundResource(R.drawable.item);
tv2.setPadding(10, 15, 10, 15);
tv2.setTextSize(13);
row1.addView(tv2);
TextView tv3 = new TextView(this);
tv3.setText(cn.getSIZE());
tv3.setTextColor(Color.BLACK);
tv3.setGravity(Gravity.CENTER);
tv3.setBackgroundResource(R.drawable.item);
tv3.setPadding(10, 15, 10, 15);
tv3.setTextSize(13);
row1.addView(tv3);
TextView tv4 = new TextView(this);
tv4.setText(cn.getUNAME());
tv4.setTextColor(Color.BLACK);
tv4.setGravity(Gravity.CENTER);
tv4.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv4.setBackgroundResource(R.drawable.item);
tv4.setPadding(10, 15, 10, 15);
tv4.setTextSize(13);
row1.addView(tv4);
TextView tv5 = new TextView(this);
tv5.setText(cn.getRETAIL());
tv5.setTextColor(Color.BLACK);
tv5.setGravity(Gravity.CENTER);
tv5.setBackgroundResource(R.drawable.item);
tv5.setPadding(10, 15, 10, 15);
tv5.setTextSize(13);
row1.addView(tv5);
TextView tv7 = new TextView(this);
tv7.setText(cn.getWHOLESALE());
tv7.setTextColor(Color.BLACK);
tv7.setGravity(Gravity.CENTER);
tv7.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv7.setBackgroundResource(R.drawable.item);
tv7.setPadding(10, 15, 10, 15);
tv7.setTextSize(13);
row1.addView(tv7);
TextView tv8 = new TextView(this);
tv8.setText(cn.getTRADE());
tv8.setTextColor(Color.BLACK);
tv8.setGravity(Gravity.CENTER);
tv8.setBackgroundResource(R.drawable.item);
tv8.setPadding(10, 15, 10, 15);
tv8.setTextSize(13);
row1.addView(tv8);
TextView tv9 = new TextView(this);
tv9.setText(cn.getPERCENTAGE());
tv9.setTextColor(Color.BLACK);
tv9.setGravity(Gravity.CENTER);
tv9.setBackgroundResource(R.drawable.item);
tv9.setPadding(10, 15, 10, 15);
tv9.setTextSize(13);
row1.addView(tv9);
TextView tv10 = new TextView(this);
tv10.setText(cn.getTAX());
tv10.setTextColor(Color.BLACK);
tv10.setGravity(Gravity.CENTER);
tv10.setBackgroundResource(R.drawable.item);
tv10.setPadding(10, 15, 10, 15);
tv10.setTextSize(13);
row1.addView(tv10);
TextView tv11 = new TextView(this);
tv11.setText(cn.getSUBCATAGARY());
tv11.setTextColor(Color.BLACK);
tv11.setGravity(Gravity.CENTER);
tv11.setBackgroundResource(R.drawable.item);
tv11.setPadding(10, 15, 10, 15);
tv11.setTextSize(13);
row1.addView(tv11);
TextView tv12 = new TextView(this);
tv12.setText(cn.getCATEGARY());
tv12.setTextColor(Color.BLACK);
tv12.setGravity(Gravity.CENTER);
tv12.setBackgroundResource(R.drawable.item);
tv12.setPadding(10, 15, 10, 15);
tv12.setTextSize(13);
row1.addView(tv12);
TextView tv13 = new TextView(this);
tv13.setText(cn.getCOMPANY());
tv13.setTextColor(Color.BLACK);
tv13.setGravity(Gravity.CENTER);
tv13.setBackgroundResource(R.drawable.item);
tv13.setPadding(10, 15, 10, 15);
tv13.setTextSize(13);
row1.addView(tv13);
TextView tv14 = new TextView(this);
tv14.setText(cn.getTYPE());
tv14.setTextColor(Color.BLACK);
tv14.setGravity(Gravity.CENTER);
tv14.setBackgroundResource(R.drawable.item);
tv14.setPadding(10, 15, 10, 15);
tv14.setTextSize(13);
row1.addView(tv14);
TextView tv16 = new TextView(this);
tv16.setText(cn.getPACKSIZE());
tv16.setTextColor(Color.BLACK);
tv16.setGravity(Gravity.CENTER);
tv16.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv16.setBackgroundResource(R.drawable.item);
tv16.setPadding(5, 15, 5, 15);
tv16.setTextSize(13);
row1.addView(tv16);
TextView tv17 = new TextView(this);
tv17.setText(cn.getWEIGHT());
tv17.setTextColor(Color.BLACK);
tv17.setGravity(Gravity.CENTER);
tv17.setBackgroundResource(R.drawable.item);
tv17.setPadding(5, 15, 5, 15);
tv17.setTextSize(13);
row1.addView(tv17);
TextView tv18 = new TextView(this);
tv18.setText(cn.getWEIGHTUNIT());
tv18.setTextColor(Color.BLACK);
tv18.setGravity(Gravity.CENTER);
tv18.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv18.setBackgroundResource(R.drawable.item);
tv18.setPadding(5, 15, 5, 15);
tv18.setTextSize(13);
row1.addView(tv18);
TextView tv19 = new TextView(this);
tv19.setText(cn.getCURRENTSTOCK());
tv19.setTextColor(Color.BLACK);
tv19.setGravity(Gravity.CENTER);
tv19.setBackgroundResource(R.drawable.item);
tv19.setPadding(5, 15, 5, 15);
tv19.setTextSize(13);
row1.addView(tv19);
t1.addView(row1);
}}t=0;
}
catch (Exception e){
//t2.setText(e.toString());
}
}
else{
// t2.setText("DataBase is not Readable");
}
}
}
}
尝试这种方法以获得更好的结果,我认为这可能有16列,