Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pull strings from an array adapted listview for a clicked list item
    text
    copied!<p>ok so i have an array adapted listview (the array adapting is done in another class).. i just got the click listener working for the list but now i want set it up so that when i click an item it pulls the strings from the clicked item and piggybacks them on the intent to a new activity.. i figure im supposed to use intent.putextra however im not sure how to pull the correct strings corresponding to the item that i click on.. my code is below.. im simply lost to be honest</p> <pre><code>//Initialize the ListView lstTest = (ListView)findViewById(R.id.lstText); //Initialize the ArrayList alrts = new ArrayList&lt;Alerts&gt;(); //Initialize the array adapter notice with the listitems.xml layout arrayAdapter = new AlertsAdapter(this, R.layout.listitems,alrts); //Set the above adapter as the adapter for the list lstTest.setAdapter(arrayAdapter); //Set the click listener for the list lstTest.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView adapterView, View view, int item, long arg3) { Intent intent = new Intent( HomePageActivity.this, PromotionActivity.class ); finish(); startActivity(intent); } }); </code></pre> <p>my alerts class..</p> <pre><code>public class Alerts { public String cityid; public String promoterid; public String promoshortcontent; public String promocontent; public String promotitle; public String locationid; public String cover; @Override public String toString() { return "City: " +cityid+ " Promoter: " +promoterid+ "Short Promotion: " +promoshortcontent+ "Promotion: " +promocontent+ "Title: " +promotitle+ "Location: " +locationid+ "Cover: " +cover+ "$"; } </code></pre> <p>}</p> <p>anddddd my alertsadapter class..</p> <pre><code>public class AlertsAdapter extends ArrayAdapter&lt;Alerts&gt; { int resource; String response; Context context; //Initialize adapter public AlertsAdapter(Context context, int resource, List&lt;Alerts&gt; items) { super(context, resource, items); this.resource=resource; } @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout alertView; //Get the current alert object Alerts al = getItem(position); //Inflate the view if(convertView==null) { alertView = new LinearLayout(getContext()); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi = (LayoutInflater)getContext().getSystemService(inflater); vi.inflate(resource, alertView, true); } else { alertView = (LinearLayout) convertView; } //Get the text boxes from the listitem.xml file TextView textPromo =(TextView)alertView.findViewById(R.id.txtPromo); TextView textPromoter =(TextView)alertView.findViewById(R.id.txtPromoter); TextView textLocation =(TextView)alertView.findViewById(R.id.txtLocation); //Assign the appropriate data from our alert object above textPromo.setText(al.promocontent); textPromoter.setText(al.promoterid); textLocation.setText(al.locationid); return alertView; } </code></pre> <p>}</p>
 

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