0

我正在尝试向我的列表视图添加一个标题,但只添加了标题......剩余的列表视图仍然是空的......并且知道我做错了什么???

这是我的代码...

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();
        }
    }
4

1 回答 1

0

尝试这个

LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);

参考Android:将静态标题添加到ListActivity的顶部

于 2012-12-11T09:57:24.850 回答