我正在创建一个动态列表视图,我不需要数据库来存储数据,无论我添加什么数据,它都必须显示在我的列表视图中。现在它没有显示在我的列表视图中。项目列表活动.java
public class Prayers extends ListActivity{
private static final int ACTIVITY_CREATE=0;
/** Items entered by the user is stored in this ArrayList variable */
ArrayList<String> list = new ArrayList<String>();
/** Declaring an ArrayAdapter to set items to ListView */
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prayers_list);
fillData();
registerForContextMenu(getListView());
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
//btn.setOnClickListener(listener);
/** Setting the adapter to the ListView */
setListAdapter(adapter);
}
private void fillData() {
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_insert:
createProject();
return true;
}
return super.onMenuItemSelected(featureId, item);
}
private void createProject() {
Intent i = new Intent(this, PrayersEditActivity.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_prayers_list, menu);
return true;
}
}
这是我的项目editactivity.java
public class PrayersEditActivity extends Activity{
private EditText mTitleText;
private Button mConfirmButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prayers_edit);
mTitleText = (EditText) findViewById(R.id.title);
mConfirmButton = (Button) findViewById(R.id.confirm);
registerButtonListenersAndSetDefaultText();
}
private void registerButtonListenersAndSetDefaultText() {
mConfirmButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//saveState();
String title = mTitleText.getText().toString();
mTitleText.setText("");
//adapter.notifyDataSetChanged();
setResult(RESULT_OK);
Toast.makeText(PrayersEditActivity.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
finish();
}
});
}
/*private void saveState() {
//mTitleText = (EditText) findViewById(R.id.title);
String title = mTitleText.getText().toString();
mTitleText.setText("");
adapter.notifyDataSetChanged();
}*/
}
在我的列表视图中,如果我单击菜单按钮,它必须转到编辑页面,在他们单击保存按钮后我必须添加项目,它必须显示在我的列表视图中,现在它不显示在我的列表视图中。