I have a multiple TextView
s per list item in my ListView
. I've learned to write a proper getView
method I believe but I'm not sure ho do I use setAdapter
to call that method.
private static String[] project = {"proj1","proj2"};
private static String[] workRequests = {"requirement gathering", "design"};
private static String[] startDate = {"02/21/2012","07/15/2011"};
private static String[] status = {"WIP","DONE"};
ListView mListView;
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);
mListView.setAdapter(
// How do I set the adapter?
);
}
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);
}
((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;
}
This is the xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Include Action Bar -->
<include layout="@layout/actionbar_layout" />
<ListView
android:id="@+id/dashboardList"
style="@style/LeftHeaderText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@drawable/innerdashboard_bg"
android:textColor="@color/textColor" >
<TextView android:id="@+id/project" />
<TextView android:id="@+id/work_request" />
<TextView android:id="@+id/start_date" />
<TextView android:id="@+id/status" />
</ListView>
</LinearLayout>
I've tried a few ways, none of which worked. Could anyone please suggest how to set the adapter in this case? Thanks!
getView()
part of yourAdapter
class? – Buzzer