我是Android新手,我需要发送一条包含以下内容的短信 例如:“1”+“\ n”+“f_name”+“l_name”+“roll”;我将这些信息存储在arraylist中。任何人都建议我如何执行操作。我已经完成了一些操作。
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
System.out.println("RN-->>created parser");
SAXXMLHandlerChalanForm ch = new SAXXMLHandlerChalanForm();
xr.setContentHandler(ch);
xr.parse(new InputSource(getAssets().open("Chalan.xml")));
ArrayList<ChalanFormDTO> chalanList = ch.getChalanData();
System.out.println("size of ChalanList" + chalanList.size());
for (int i = 0; i < chalanList.size(); i++) {
if (chalanNum.equalsIgnoreCase(chalanList.get(i).getChalanNo()))
{ text_chalanNo.setText(chalanList.get(i).getChalanNo());
text_buyName.setText(chalanList.get(i).getBuyerName());
text_date.setText(chalanList.get(i).getDates());
text_sales.setText(chalanList.get(i).getSales());
System.out.println("Size of LISTOFITEMS:\n"
+ chalanList.get(i).getListOfStock().size());
for (int j = 0; j < chalanList.get(i).getListOfStock()
.size(); j++) {
TableRow tr1 = new TableRow(this);
tr1.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
TextView tv9 = new TextView(this);
tv9.setText(String.valueOf(j+1));
tv9.setBackgroundResource(R.drawable.border_top);
tv9.setTextColor(getResources().getColor(R.color.Black));
tv9.setLayoutParams(new TableRow.LayoutParams(dpwidth/2,
LayoutParams.WRAP_CONTENT));
tv9.setGravity(Gravity.CENTER_HORIZONTAL);
tv9.setMinimumWidth(dpwidth);
tr1.addView(tv9);
TextView tv4 = new TextView(this);
tv4.setText(chalanList.get(i).getListOfStock().get(j)
.getName());
tv4.setBackgroundResource(R.drawable.border_top);
tv4.setTextColor(getResources().getColor(R.color.Black));
tv4.setLayoutParams(new TableRow.LayoutParams(dpwidth,
LayoutParams.WRAP_CONTENT));
tv4.setGravity(Gravity.CENTER_HORIZONTAL);
tv4.setMinimumWidth(dpwidth);
tr1.addView(tv4);
TextView tv6 = new TextView(this);
tv6.setText(chalanList.get(i).getListOfStock().get(j)
.getQuantity());
tv6.setBackgroundResource(R.drawable.border_top);
tv6.setTextColor(getResources().getColor(R.color.Black));
tv6.setLayoutParams(new TableRow.LayoutParams(dpwidth,
LayoutParams.WRAP_CONTENT));
tv6.setGravity(Gravity.CENTER_HORIZONTAL);
tv6.setMinimumWidth(dpwidth);
tr1.addView(tv6);
table.addView(tr1, 3);
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
答案 0 :(得分:1)
您可以使用for循环将arraylist数据附加到stringbuffer中。
创建一个像
这样的字符串缓冲区StringBuffer strbuf = new StringBuffer();
for(int i = 0; i<chalanList.size; i++)
{
strbuf.append("1\n");
strbuf.append("f_name: "+chalanList.get(i).f_name);
strbuf.append(chalanList.get(i).getChalanNo());
strbuf.append(chalanList.get(i).getBuyerName());
. . .
}
插入完成后将其发送给短信。