我正在尝试为我的列表视图添加一个标题,但只添加了标题...剩下的listview仍然是空的....并且知道我做错了什么???
这是我的代码......
public class Settings extends Activity {
String setting[];
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
setting = new String[] { "Reset Password" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, setting);
lv = (ListView) findViewById(R.id.Lvsettings);
View header = (View) getLayoutInflater().inflate(R.layout.header,
null);
lv.addHeaderView(header);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
startact(position);
}
});
} catch (Exception e) {
Toast.makeText(getApplicationContext(), String.valueOf(e),
Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:0)
试试这个
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);
参考Android: Adding static header to the top of a ListActivity