-
-
Save serhatsezer/bfc205aedc3222f4a4ea to your computer and use it in GitHub Desktop.
HeaderListView implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Intent getExtras = getIntent(); | |
jobDetailID = getExtras.getStringExtra("id"); | |
HeaderListView listView = new HeaderListView(this); | |
listView.setAdapter(new SectionAdapter() { | |
@Override | |
public int numberOfSections() { | |
// TODO Auto-generated method stub | |
return 4; | |
} | |
@Override | |
public int numberOfRows(int section) { | |
// TODO Auto-generated method stub | |
return 35; | |
} | |
@Override | |
public View getRowView(int section, int row, View convertView, ViewGroup parent) { | |
if (convertView == null) { | |
convertView = (TextView) getLayoutInflater().inflate(getResources().getLayout(android.R.layout.simple_list_item_1), null); | |
} | |
((TextView) convertView).setText("Section " + section + " Row " + row); | |
return convertView; | |
} | |
@Override | |
public int getSectionHeaderViewTypeCount() { | |
return 2; | |
} | |
@Override | |
public int getSectionHeaderItemViewType(int section) { | |
return section % 2; | |
} | |
@Override | |
public View getSectionHeaderView(int section, View convertView, ViewGroup parent) { | |
Toast.makeText(getApplicationContext(), "sample", Toast.LENGTH_SHORT).show(); | |
Log.i("Section", "works"); | |
Log.i("JobDetailActivity", "ok!"); | |
if (convertView == null) { | |
Log.i("convertview", "null"); | |
if (getSectionHeaderItemViewType(section) == 0) { | |
convertView = (TextView) getLayoutInflater().inflate(R.layout.list_header, null); | |
} else { | |
convertView = getLayoutInflater().inflate(R.layout.list_header, null); | |
} | |
} else { | |
Log.i("convertview is not null", "yes"); | |
} | |
if (getSectionHeaderItemViewType(section) == 0) { | |
((TextView) convertView).setText("Header for section " + section); | |
} else { | |
((TextView) convertView.findViewById(android.R.id.text1)).setText("Header for section " + section); | |
((TextView) convertView.findViewById(android.R.id.text2)).setText("Has a detail text field"); | |
} | |
switch (section) { | |
case 0: | |
convertView.setBackgroundColor(getResources().getColor(R.color.bg_color)); | |
break; | |
case 1: | |
convertView.setBackgroundColor(getResources().getColor(R.color.header_normal)); | |
break; | |
case 2: | |
convertView.setBackgroundColor(getResources().getColor(R.color.header_red_color)); | |
break; | |
case 3: | |
convertView.setBackgroundColor(getResources().getColor(R.color.header_normal)); | |
break; | |
} | |
return convertView; | |
} | |
@Override | |
public Object getRowItem(int section, int row) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
}); | |
setContentView(listView); | |
prepareJobDetail(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You missed / forgot the
method call in your SectionAdapter.