我有一个活动,它从另一个活动加载 sharedPreference,并在我编译我的应用程序时使用 arrayAdpter 将一些数据从 sharedPreferenece 放入 listView 强制关闭这是我的代码:
public class DawaaActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
Button add;
ListView dataList;
private SharedPreferences emportPref;
String[] dawaaList;
String theName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialaiz();
emportPref = getSharedPreferences("dawaaData", MODE_PRIVATE);
theName = emportPref.getString("subject", "no data found");
Toast.makeText(this, theName, Toast.LENGTH_LONG).show();
dawaaList[0] = theName;
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dawaaList);
dataList.setAdapter(adapter);
}
private void initialaiz() {
// TODO Auto-generated method stub
add = (Button) findViewById(R.id.button3);
dataList = (ListView) findViewById(R.id.myListView);
add.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Intent data = new Intent(DawaaActivity.this,SettingActivity.class);
startActivity(data);
}
如果代码提示,当我制作这两行时:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dawaaList);
dataList.setAdapter(adapter)
该应用程序运行良好
但不填充 listView 当然
请帮帮我