I am making an android application and implementing a table so I am making all Text Boxes and Edit Boxes dynamically and also giving their Text Size dynamically but it is not coming according to their device size. Please help me thanks in advance. I wanted to make my app size compatible according to device.
tbrow = new TableRow(context);
tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, 45));
// tbrow.setPadding(5, 0, 5,0);
// serial no.
TextView tv = new TextView(context);
tv.setGravity(Gravity.CENTER);
if (buttonchangeCount > 0 && i < saveDataCount) {
cursor.moveToNext();
int id = cursor.getInt(cursor.getColumnIndex("loans_id"));
receiptId.add("" + id);
tv.setText(id + "");
} else {
tv.setText((addButtCount) + "");
}
tv.setPadding(10, 10, 5, 10);
tv.setTextColor(res.getColor(R.color.mainColor));
if (Login.width >= 1000) {
tv.setTextSize(25);
tv.setWidth(121);
} else if (Login.width >= 480 && Login.width < 1000) {
tv.setTextSize(15);
tv.setWidth(242);
tv.setHeight(96);
} else if (Login.width >= 320 && Login.width < 480)
tv.setTextSize(12);
tv.setBackgroundResource(R.drawable.cell_shape_color);
sr_no.add(tv);
tbrow.addView(tv);
// Bank loan type.
final Button butt = new Button(context);
butt.setId(i);
butt.setGravity(Gravity.CENTER);
butt.setPadding(5, 10, 5, 10);
bankLoanType.add(butt);
if (buttonchangeCount > 0 && i < saveDataCount) {
String str = cursor.getString(cursor.getColumnIndex("loan_type"));
butt.setText(str);
loanstatuslist.clear();
loanstatuslist.add("New");
loanstatuslist.add("Renew");
int id1 = butt.getId();
if (cursor.getString(cursor.getColumnIndex("loan_type")).equalsIgnoreCase("Term Loan(TL)")) {
loanstatuslist.remove(1);
loan_status1.get(id1).setText("New");
}
// } else {
// //loan_status1.get(id1).setText("Select Loan Status");
// }
//
} else {
// butt.setText("Select Loan Type");
}
butt.setTextColor(res.getColor(R.color.mainColor));
if (Login.width >= 1000) {
butt.setTextSize(25);
butt.setWidth(300);
} else if (Login.width >= 480 && Login.width < 1000)
{
butt.setTextSize(14);
butt.setWidth(604);
butt.setHeight(92);
} else if (Login.width >= 320 && Login.width < 480)
butt.setTextSize(12);
butt.setBackgroundResource(R.drawable.cell_shape_color);
butt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
final int id11 = butt.getId();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
View layout = BankLoanFragment.this.inflater.inflate(R.layout.list_view,
BankLoanFragment.this.container, false);
ListView listView = (ListView) layout.findViewById(R.id.listView);
final ArrayList<String> list = new ArrayList<String>();
list.add("Cash Credit Limit(CCL)");
list.add("Term Loan(TL)");
OnlyTextAdapter adapter = new OnlyTextAdapter(context, list);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
builder.setView(layout);
final AlertDialog ad = builder.create();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
butt.setText(list.get(position).toString());
String bt = butt.getText().toString();
final int id1 = butt.getId();
Log.d("bankLoan", "id1=" + id1);
// =
// bankLoanType.get(id1).getText().toString().trim();
//
if (bt.equals("Select Loan Type")
&& (loanNumber.get(id1).getText().toString().trim().length() <= 0)) {
Log.d("bankLoan", "in IF case");
cmnBehave.alertMsg("Select Loan type and LoanNumber first.", "Loan Status");
// ad.dismiss();
} else {
loanstatuslist.clear();
String str = loan_status1.get(id1).getText().toString();
loanstatuslist.add("New");
loanstatuslist.add("Renew");
if (bt.equals("Term Loan(TL)")) {
loanstatuslist.remove(1);
loan_status1.get(id1).setText("New");
// ad.dismiss();
} else
loan_status1.get(id1).setText(str);
}
ad.dismiss();
}
});
// if(cursor.getInt(cursor.getColumnIndex("bank_loan_status")))
if (dbutil.getnewStatusIsExists(shgid, meetingDate,
(loanNumber.get(id11).getText().toString().trim())) == 0) {
// cmnBehave.alertMsg("You have already taken Loan, you
// can renew Loan.", "Action");
ad.show();
}
}
});