Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not sure if I got your problem correctly but I guess your Main activity is calling an activity that has a ListView and then you want the result back in the Main activity, right?</p> <p>If so, the code you displayed is not the right way to do what you want. What you are looking for is to use <code>StartActivityForResult</code> and Overriding the <code>onActivityResult</code> method in your main activity.</p> <p>I don't know exactly how to use Monodroid and C# but I can give you an example in Java that I am sure will help you understand how to get what you want:</p> <p>Let's say my ListView activity is called <strong>myList</strong> and extends a ListActivity and my main activity is called <strong>MainActivity</strong>. Below is the OnListItemClick method of <strong>myList</strong>:</p> <pre><code>@Override protected void onListItemClick(ListView l, View v, int position, long id){ super.onListItemClick(l, v, position, id); String text = String.valueOf(labels[position]); // Create the intent with the extras Intent send = new Intent(); send.putExtra("text_from_list", text); // Set the result to OK (meaning the extras are put as expected by the caller) setResult(RESULT_OK, send); // you need this so the caller (MainActivity) knows that the user completed // this activity (myList) as expected (clicking on the item to return a result) // and didn't just leave the activity (back button) // Close this List Activity finish(); } </code></pre> <p>Below is the method in my <strong>Main Activity</strong> that calls myList:</p> <pre><code>private void callListActivity(){ Intent call = new Intent(MainActivity.this, myList.class); startActivityForResult(call, 1); // The second field is just a number to identify which activity // returned a result when a result is received (you can have // several calls to different activities expecting results from // each one of them). This number is called requestCode. } </code></pre> <p>You will have to Override the <code>onActivityResult</code> in your <strong>MainActivity</strong> with something like this:</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Check if the returned data came from myList (requestCode 1) and if // data was actually received (check if resultCode = RESULT_OK) if (requestCode == 1) { if (resultCode == RESULT_OK) { String text = data.getStringExtra("text_from_list"); // you have to use the same string identifier you used // when you put the extra in the Intent in myList TextView tvYearChange = (TextView)findViewById(R.id.tvYearchange); tvYearChange.setText(text); } else { // Do something if the Activity didn't return data // (resultCode != RESULT_OK) } } // If you are expecting results from other Activities put more if // clauses here with the appropriate request code, for example: // if (requestCode == 2) { // DoSomething; // } // And so on... } </code></pre> <p>It shouldn't be hard to modify this Java code to C# code that you can use with Monodroid. Also, take a look at <a href="http://developer.android.com/reference/android/app/Activity.html#StartingActivities" rel="nofollow">this link</a> from the Android Official Documentation, they have a lot of useful stuff there.</p> <p>I hope this helps you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload