Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(1) There is one way to pass value from Adapter to Activity on which adapter is set,</p> <p>i.e we write listview.setadapter(xyzadapter); in MainActivity, and we want to pass value from xyzadapter to MainActivity, then only one way I know, make one interface, define one method in that with parameters for passing value, and then implement it on adapter class,</p> <p>(2) If we want to pass values from adapter to another activity in which it is not set, then we can use putExtra method to pass value,</p> <p>Let me know if you have any issue...</p> <p><strong>Edited:</strong> for (1) answer</p> <p>make one interface in your main package:</p> <pre><code>public interface DataTransferInterface { public void setValues(ArrayList&lt;?&gt; al); } </code></pre> <p>in your adapter class make object of Interface:</p> <p>below this line public class CartAdapter extends BaseAdapter { and before constructor:</p> <pre><code>DataTransferInterface dtInterface; </code></pre> <p>in your construction pass this interface</p> <p>in CartAdapter use this constructor:</p> <pre><code>public CartAdapter(Activity a, DataTransferInterface dtInterface) { // TODO Auto-generated constructor stub activity = a; this.dtInterface = dtInterface; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } </code></pre> <p>and use dtInterface.setValues(your Values to pass to Activity)</p> <p>Now in your CartActivity.java</p> <p>implement that interface like:</p> <pre><code>public class CartActivity extends Activity implements DataTransferInterface { </code></pre> <p>and change </p> <pre><code>mViewCartAdpt = new CartAdapter(CartActivity.this); </code></pre> <p>to</p> <pre><code>mViewCartAdpt = new CartAdapter(CartActivity.this, this); </code></pre> <p>now you will see red line below CartActivity (just move your mouse cursor on CartActivity) that shows add unimplemented methods, click on that will override setValues method</p> <pre><code>@Override public void setValues(ArrayList&lt;?&gt; al) { // TODO Auto-generated method stub } </code></pre> <p>you can use Any type of data to pass instead of ArrayList</p> <p>Let me know if you have any ussue:</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.
    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