0

这是我的代码,在黑莓中运行良好并获得 3 个显示在 textview 中的响应,但是当我在 android 中使用此代码时,只显示 1 次而不是 3 次,所以我如何使用 1 个文本视图打印 3 次结果?

  for (int x = 7; x <= xmlRespone.length - 1; x = x + 3) {

                    TextView lblTransactionDate = 
  (TextView)     findViewById(R.id.lblTransactionDate);
                    lblTransactionDate.setText("Transaction   
 Date : "+ xmlRespone[x][1]);              





     lblTransactionDate.setTextColor(getResources().getColor
  (R.color.text_color_slateblue));

                    TextView lblAmount = (TextView)   
      findViewById(R.id.lblAmount);
                    lblAmount.setText("Amount : " +    
      xmlRespone[x + 1][1]);
4

2 回答 2

1

请参阅TextView.append(CharSequence text)以显示 Single TextView 中的所有值。将您的代码更改为:

    TextView lblTransactionDate = (TextView)findViewById(R.id.lblTransactionDate);

    TextView lblAmount = (TextView)findViewById(R.id.lblAmount);

    for (int x = 7; x <= xmlRespone.length - 1; x = x + 3) {
// if you want to clear Prev value
    lblTransactionDate.setText(""); 
    lblTransactionDate.setText("Transaction  Date : "+ xmlRespone[x][1]);        
    // if you want to append with Prev Value
    lblTransactionDate.append("Transaction  Date : "+ xmlRespone[x][1]);      

    lblTransactionDate.setTextColor(getResources().getColor(R.color.text_color_slateblue));

    // if you want to clear Prev value
    lblAmount.setText("Amount : " + xmlRespone[x + 1][1]);
    // if you want to append with Prev Value
    lblAmount.append("Amount : " +  xmlRespone[x + 1][1]);
于 2012-09-06T11:50:56.223 回答
0

嗯... textview 将采用所有三个值,但仅显示最后一个值。如果要向其附加文本,请执行

text.setText(text.getText() + "new_text");

或者你可以使用

text.append("new_text");

但也许您只是想向您的用户发布类似“通知”的消息,Toast 就是这样使用的

Toast.makeText(context, "Signing in with default user.", Toast.LENGTH_LONG).show();

只要确保从 UI 线程调用 Toast,如果不使用它

public void fireToast(final String toast)
{
    handler.post(new Runnable()
    {
        @Override
        public void run()
        {
            Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
        }
    });
}
于 2012-09-06T11:49:21.543 回答