Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Your getView() code needs to go into a class that extends BaseAdapter or one of its subclasses.</strong> </p> <p>One way to do this is to create a private class within your MyDashboardActivity. Here's a quick example below (some additional code will be required). You'll probably also want a custom object to associate all the things you want to display in one list item. Instead of multiple arrays, have one array of a custom type that has properties for each value you are tracking.</p> <p>One more thing: your four TextViews should go into their own layout file (see list_item.xml <a href="http://developer.android.com/resources/tutorials/views/hello-listview.html" rel="nofollow">here</a>). That item layout file gets hooked up through the constructor of the custom adapter (I added a comment in the code below to highlight this).</p> <pre><code>protected CustomAdapter mAdapter; public class MyDashboardActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboard); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboardList); mAdapter = new CustomAdapter(this, &lt;array to be adapted&gt;); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter&lt;String&gt; { protected Context mContext; protected ArrayList&lt;String&gt; mItems; public CustomAdapter(Context context, ArrayList&lt;String&gt; items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View convertView, ViewGroup parent) { System.out.println("enters"); if(convertView == null){ convertView = LayoutInflater.from(this).inflate(R.layout.mydashboard,null); } // You'll need to use the mItems array to populate these... ((TextView) convertView.findViewById(R.id.project)).setText(project[position]); ((TextView) convertView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) convertView.findViewById(R.id.start_date)).setText(startDate[position]); ((TextView) convertView.findViewById(R.id.status)).setText(status[position]); return convertView; } } } </code></pre>
 

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