Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating custom Adapter class to avoid for custom listview
    primarykey
    data
    text
    <p>I am building my own ListView based off of <a href="http://www.thepcwizard.in/2012/09/android-creating-custom-listview-for.html" rel="nofollow">this</a> tutorial.</p> <p>this line: <code>MessageDetails msg = _data.get(position);</code> in his code is giving me a problem. I am obviously getting an type error with this line. I do not understand how his code was working like this. What should I be doing differently so that I can have it work the way his does. </p> <p><em>EDIT</em></p> <p>I am aware of the fact that the problem with this line is that it is trying to put two different types together <code>MessageDetails</code> and <code>ArrayList&lt;String&gt;</code>. His tutorial doesn't give me a good way of doing as I am getting the error and he apparently did not. </p> <p>my adapter class</p> <pre><code>public class MenuItemAdapter extends BaseAdapter { private ArrayList&lt;String&gt; _data; Context _c; MenuItemAdapter(ArrayList&lt;String&gt; data, Context c){ _data = data; _c = c; } public int getCount() { return _data.size(); } public Object getItem(int position) { return _data.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.menuitemrow, null); } ImageView image = (ImageView) v.findViewById(R.id.MIR_itemImage); TextView itemName = (TextView)v.findViewById(R.id.MIR_itemImage); TextView itemDescription = (TextView)v.findViewById(R.id.MIR_itemDescription); TextView itemPrice = (TextView)v.findViewById(R.id.MIR_itemPrice); TextView itemOther = (TextView)v.findViewById(R.id.MIR_itemOther); // Create instance of MenuItemDetail and then assign MenuItemDetail mid = _data.get(position); image.setImageResource(mid.icon); itemName.setText(mid.itemName); itemDescription.setText(mid.itemDescription); itemPrice.setText(mid.itemPrice); itemOther.setText(mid.itemOther); return v; } } </code></pre> <p>and this is my <code>MenuItemDetail</code> class which is very similar to his just with my fields instead.</p> <pre><code>public class MenuItemDetail { int icon; String itemName; String itemDescription; String itemPrice; String itemOther; public int getIcon() { return icon; } public void setIcon(int icon) { this.icon = icon; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } public String getItemDescription() { return itemDescription; } public void setItemDescription(String itemDescription) { this.itemDescription = itemDescription; } public String getItemPrice() { return itemPrice; } public void setItemPrice(String itemPrice) { this.itemPrice = itemPrice; } public String getItemOther() { return itemOther; } public void setItemOther(String itemOther) { this.itemOther = itemOther; } } </code></pre> <p>Any help and explanation would be appreciated.</p> <p>I also had to fix the <code>ArrayList</code> issue as well where it needed the <code>ArrayList&lt;String&gt;</code>. Not sure if that change is where it went wrong. </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