在一個 RelativeLayout 有兩個 TextViews ,布局像一個按鈕。用戶點擊"button" 時,我發送一個TextView到一個resulting TextView,把第二個TextView 放到一個list中。這些都是在相同的activity中。
用戶持續點擊 "button"時,就會用很多items填充ListView。
我的問題是如何發送填充到 resulting TextView和ListView的內容到一個新的activity?
我可以發送resulting TextView的內容,但是不能根據發送到一個新的 Activity 中ListView的內容獲取別的信息。
第一個 Activity:
public class MenuView1Activity extends ListActivity {
private double overallTotalproduct;
public static TextView resultTextView;
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
private Button whateverButton;
TextView inputPrice;
RelativeLayout lay1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.menuview);
adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
listItems);
setListAdapter(adapter);
whateverButton = (Button)findViewById(R.id.whateverButton);
inputPrice= (TextView)findViewById(R.id.inputPrice);
lay1= (RelativeLayout)findViewById(R.id.lay1);
//Total Box
final TextView textViewtotalproduct = (TextView) findViewById(R.id.inputPrice);
final TextView textView1 = (TextView) findViewById(R.id.m1aa);
final String stringm1aa = textView1.getText().toString();
final double intm1aa = Double.parseDouble(stringm1aa);
final TextView textView1a = (TextView) findViewById(R.id.m1a);
final String stringm1a = textView1a.getText().toString();
lay1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
listItems.add("$"+intm1aa +"-"+ stringm1a);
adapter.notifyDataSetChanged();
resultTextView.setText(stringm1a);
overallTotalproduct = intm1aa + overallTotalproduct;
textViewtotalproduct.setText(String.valueOf(overallTotalproduct));
}
});
public void onwhateverPress(View v) {
Intent whateverIntent = new Intent(this, WhateverActivity.class);
if (whateverResult.iswhateveranicewhatever()) {
final TextView daplane =(TextView)findViewById(R.id.date);
String watch = daplane.getText().toString();
startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class)
.putExtra("date",(CharSequence)watch)
.putStringArrayListExtra("list", (ArrayList<String>) listItems));
finish();
第二個Activity
Intent id11 = getIntent();
if (id11.getCharSequenceExtra("list") != null) {
final TextView setmsg = (TextView)findViewById(R.id.saleNotes);
setmsg.setText(id11.getCharSequenceExtra("list"));
}
你可以使用ListView.getAdapter()
從 ListView 中獲取所有更新的 items,然後使用 Intent.putStringArrayListExtra
把 ArrayList 從一個 Activity 中發送到另一個當中去。
startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class)
.putExtra("date",(CharSequence)watch)
.putStringArrayListExtra("list", (ArrayList<String>)getListView().getAdapter()));
finish();