我想用从(string.xml)和图像中提取的文本填充listview。
我这样做了但是我得到了NPE
你能帮助我吗?
谢谢

public class Menu_activity extends ListActivity {
int[] img = { R.drawable.01, R.drawable.1, R.drawable.2,
        R.drawable.3, R.drawable.4,
        R.drawable.5};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getListView().setDividerHeight(1);
    getListView().setAdapter(new BindDataAdapter(this, img, men));

}
private String[] men = getResources().getStringArray(R.array.men);

最佳答案

改成

private String[] men;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    men = getResources().getStringArray(R.array.men); // inside onCreate
    getListView().setDividerHeight(1);
    getListView().setAdapter(new BindDataAdapter(this, img, men));
}

关于android - 带有图像和数组文本的Android Listview,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19881316/

10-09 01:31