1
共有設定を使用してメモを取っています。しかし、それを編集するためにlistItemをクリックしてもう一度クリックすると、更新されていません。戻るボタンを押してもデータが更新されない
リストビューでマイMainActivity:
ListView notesListView;
static ArrayList<String> notesArrayList;
static ArrayAdapter<String> notesAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notesArrayList = new ArrayList<String>();
notesListView = (ListView) findViewById(R.id.listView);
notesArrayList.add("Example");
notesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, notesArrayList);
notesListView.setAdapter(notesAdapter);
notesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplicationContext(), EditNote.class);
intent.putExtra("position", position);
startActivity(intent);
}
});
そして、私の編集ノートアクティビティ:
EditText userNote;
int noteId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_note);
userNote = (EditText) findViewById(R.id.editTextNote);
Intent intent = getIntent();
noteId = intent.getIntExtra("position", -1);
if(noteId != -1){
userNote.setText(MainActivity.notesArrayList.get(noteId));
}
userNote.addTextChangedListener(this);
}
@Override
public void onBackPressed() {
Intent goBack = new Intent(EditNote.this, MainActivity.class);
startActivity(goBack);
finish();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
MainActivity.notesArrayList.set(noteId, String.valueOf(s));
MainActivity.notesAdapter.notifyDataSetChanged();
}
@Override
public void afterTextChanged(Editable s) {
}
}
私はこの問題は、編集ノートにonBackPressedにあると思います。しかし、私が解決策を見つけられなかったので、私は解決策を望んでいます。
ありがとうございます@アイロンマン。うん、私はそれを見落とした。愚かな間違い。しかし、 'MainActivity.java'が再び作成されたときに、新しい** Example Note **を作成するべきではありませんか? –
@AkhileshChobeyあなたが役に立った場合、あなたはその答えを受け入れることができます。 – Ironman
@AkhileshChobeyあなたを助けてうれしい。 – Ironman