使用参数启动活动

时间:2013-08-22 20:47:09

标签: c# android xamarin.android

我正在使用monodroid,我想开始一个新的活动,它有参数我不想使用intent.putextra或任何捆绑

例如,这是我的活动

namespace BoostITAndroid
{
[Activity(Label = "My Activity")]
public partial class UploadDealership : ListActivity
{

    private List<Dealership> listDealers;
    private Vehiclestoupload ul;
    private int selectedDealershipID = 0;
    private String[] Options;

    public UploadDealership(Vehiclestoupload uploadList, List<Dealership> listOfDealers)
    {
        this.ul = uploadList;
        this.listDealers = listOfDealers;
    }

所以这个活动有两个参数。

下面我正在尝试开始活动

Intent uld = new Intent(this, typeof(UploadDealership(this, listOfDealers)));
                StartActivity(uld);

但是所有内容都标有红色,所以这不起作用。

如何使用参数启动活动?

1 个答案:

答案 0 :(得分:0)

这可能对你有用。这是在活动之间传递一个字符串。

活动一:

     //Intent i = new Intent()
    EditText editText = (EditText) findViewById(R.id.editText);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
     //StartActivity(i);

关于活动二:

    // Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Capture the layout's TextView and set the string as its text
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(message);