0

我正在尝试将一些数据从一项活动发送到另一项活动,它可以正常工作,但不像我想要的那样工作。问题1-事情变得混乱。在列表项的下一个活动部分将转到不正确的 textView 并部分转到正确的 textview。问题 2- 我只能在新活动中列出 1 项,但我希望能够发送多个列表项。我认为问题在于将不同类型的 putExtra 请求组合到同一个地方,就像我在这里做的那样。

.putExtra("inputPrice",(CharSequence)pick) .putStringArrayListExtra("list", listItems)

蚂蚁帮助将不胜感激。

将数据发送到下一个活动

final TextView username =(TextView)findViewById(R.id.resultTextView);
String uname = username.getText().toString();

final TextView uplane =(TextView)findViewById(R.id.inputPrice);                     
String pick = uplane.getText().toString();

final TextView daplane =(TextView)findViewById(R.id.date);                  
String watch = daplane.getText().toString();

 startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class)
.putExtra("date",(CharSequence)watch)
.putExtra("Card Number",(CharSequence)uname)
.putExtra("inputPrice",(CharSequence)pick)
.putStringArrayListExtra("list", listItems)
);
finish();

这是下一个活动

        Intent is = getIntent();
    if (is.getCharSequenceExtra("Card Number") != null) {
        final TextView setmsg = (TextView)findViewById(R.id.saleRccn);
        setmsg.setText(is.getCharSequenceExtra("Card Number"));             
    }
        Intent it = getIntent();
    if (it.getCharSequenceExtra("date") != null) {
        final TextView setmsg = (TextView)findViewById(R.id.saleTime);
        setmsg.setText(it.getCharSequenceExtra("date"));                
    }
    Intent id1 = getIntent();
    if (id1.getCharSequenceExtra("inputPrice") != null) {
        final TextView setmsg = (TextView)findViewById(R.id.saleName);
        setmsg.setText(id1.getCharSequenceExtra("inputPrice"));
    }
    ArrayList<String> al= new ArrayList<String>();
    al = getIntent().getExtras().getStringArrayList("list");
    saleNotes= (TextView) findViewById(R.id.saleNotes); 
    saleNotes.setText(al.get(0));
4

2 回答 2

2

好吧,有几件事:

首先,您不需要将字符串转换为CharSequence.

第二件事,

定义意图,添加您的附加功能,然后调用 startActivity,如下所示:

Intent intent = new Intent(MenuView1Activity.this,RecordCheckActivity.class);
intent.putExtra("date", watch);
startActivity(intent);

第三,在检索意图时首先创建一个捆绑包,如下所示:

Bundle extras = getIntent().getExtras();
String date = extras.getString("date");

编辑:

以下是将整个数组列表转换为单个字符串并将其添加到文本视图的方法。

String listString = "";

for (String s : al)
{
    listString += s + "\t"; // use " " for space, "\n" for new line instead of "\t"
}

System.out.println(listString);
saleNotes.setText(listString);

希望这可以帮助!

于 2013-06-07T07:12:40.363 回答
1

试试这个,不要使用CharSequence只是放置字符串值

startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class)
.putExtra("date",watch)
.putExtra("Card Number",uname)
.putExtra("inputPrice",pick)
.putStringArrayListExtra("list", listItems)
);

像这样

  Intent is = getIntent();
if (is.getCharSequenceExtra("Card Number") != null) {
    final TextView setmsg = (TextView)findViewById(R.id.saleRccn);
    setmsg.setText(is.getStringExtra("Card Number"));             
}
于 2013-06-07T07:15:21.263 回答