动态添加表行表并在Android的对话框中显示它 [英] Dynamically add table row in table and display it in dialog box in android
本文介绍了动态添加表行表并在Android的对话框中显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够在它创建一个对话框并显示一个表,但我想更多的行动态添加到它。
这些行应该有(连续说3)它textviews。
请告诉我这一点。
在此先感谢
我的code,这是不工作的,如下:
struct3x5是3x5的尺寸表布局和表
布局文件1)。在单击事件code
button.setOnClickListener(新OnClickListener()
{ 公共无效的onClick(查看为arg0){ 最后弦乐NAMESPACE =http://tempuri.org/;
最后弦乐METHOD_NAME =法;
最后弦乐SOAP_ACTION =http://tempuri.org/method;
最终字符串URL =HTTP://xyz/pqr/webserv.asmx //定制对话框
最后对话的对话=新的对话框(背景下,R.style.cust_dialog);
dialog.setContentView(R.layout.struct3x5);
dialog.setTitle(XYZ);
//设置自定义对话框组件 - 文字,图片和按钮
TextView的文本1 =(TextView中)dialog.findViewById(R.id.textView1);
text1.setText(); TextView的文本2 =(TextView中)dialog.findViewById(R.id.textView2);
text2.setText(车辆(在紫胶卢比)); TextView的文字3 =(TextView中)dialog.findViewById(R.id.textView3);
text3.setText(TPP(在紫胶卢比)); TextView的文本4 =(TextView中)dialog.findViewById(R.id.textView4);
text4.setText(PL(在紫胶卢比)); TextView的text5 =(TextView中)dialog.findViewById(R.id.textView5);
text5.setText(保险(在紫胶卢比)); 的String []数据= {};
字符串x =;
INT colsize = 5;
INT行数=(data.length)/ colsize;
尝试{
SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);
SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(请求); HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,信封);
SoapObject响应=(SoapObject)envelope.getResponse();
数据=的getArray(响应);
}
赶上(例外五){
Toast.makeText(classname.this,错误,Toast.LENGTH_LONG).show();
}
CREATETABLE(数据行数); dialog.show();
}
});
2)。 _Function创建表
私人无效CREATETABLE(字符串[]的数据,诠释行数){
// TODO自动生成方法存根
的LinearLayout T1 =(的LinearLayout)findViewById(R.id.tableLayout3x5);
// TextView的[] TVA =新的TextView [data.length] 诠释计数= 0;
的for(int i = 0; I<行数;我++)
{
TR的TableRow =新的TableRow(本);
tr.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
为(中间体J = 0; J&≤(data.length /行数); J ++)
{
TextView的文本=新的TextView(本);
text.setText(数据[计数]的ToString());
text.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.CENTER_HORIZONTAL));
tr.addView(文本);
算上++;
}
t1.addView(TR,新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
}
解决方案
您可以做的东西沿着这些路线动态地添加更多的行:
的LinearLayout表=(的LinearLayout)findViewById(R.id.my_container);的TableRow text_row =新的TableRow(本);
text_row.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));//创建一个标签新的文本行
TextView的文本=新的TextView(本);
text.setText(我的文字);
text.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
text_row.addView(文本);table.addView(text_row,新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
I am able to create a dialog box and show a table in it, but i wanted to add some more rows to it dynamically.
These rows should have textviews in it (say 3 in a row).
Please direct me on this.
Thanks in advance
My code, which is not working, is as follows:
struct3x5 is layout file with table layout and table of 3x5 dimension
1). On click event code
button.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0) {
final String NAMESPACE = "http://tempuri.org/";
final String METHOD_NAME = "method";
final String SOAP_ACTION = "http://tempuri.org/method";
final String URL = "http://xyz/pqr/webserv.asmx";
// custom dialog
final Dialog dialog = new Dialog(context,R.style.cust_dialog);
dialog.setContentView(R.layout.struct3x5);
dialog.setTitle("XYZ");
// set the custom dialog components - text, image and button
TextView text1 = (TextView) dialog.findViewById(R.id.textView1);
text1.setText("");
TextView text2 = (TextView) dialog.findViewById(R.id.textView2);
text2.setText("Vehicle(Rs in Lacs)");
TextView text3 = (TextView) dialog.findViewById(R.id.textView3);
text3.setText("TPP(Rs in Lacs)");
TextView text4 = (TextView) dialog.findViewById(R.id.textView4);
text4.setText("PL(Rs in Lacs)");
TextView text5 = (TextView) dialog.findViewById(R.id.textView5);
text5.setText("Insurance(Rs in Lacs)");
String [] data = {};
String x = " ";
int colsize = 5;
int rowcount =(data.length)/colsize;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
data = getarray(response);
}
catch (Exception e){
Toast.makeText(classname.this,"error",Toast.LENGTH_LONG).show();
}
createtable(data,rowcount);
dialog.show();
}
});
2). _Function to create table
private void createtable(String[] data, int rowcount) {
// TODO Auto-generated method stub
LinearLayout t1=(LinearLayout)findViewById(R.id.tableLayout3x5);
//TextView[] tva= new TextView[data.length];
int count =0;
for(int i=0;i<rowcount;i++)
{
TableRow tr=new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
for(int j=0;j<(data.length/rowcount); j++)
{
TextView text = new TextView(this);
text.setText(data[count].toString());
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
tr.addView(text);
count++;
}
t1.addView(tr, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
}
解决方案
You can do something along these lines to dynamically add more rows:
LinearLayout table = (LinearLayout)findViewById(R.id.my_container);
TableRow text_row = new TableRow(this);
text_row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// create new text row for label
TextView text = new TextView(this);
text.setText("My Text");
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
text_row.addView(text);
table.addView(text_row, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
这篇关于动态添加表行表并在Android的对话框中显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文