2016-06-19 3 views
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 편집에 참고에있다 생각합니다. 그러나 내가 찾지 못한 해결책을 원합니다. 이미 단순히 onBackPressed() 방법에 MainActivity.java에가는 때 다시 왜 MainActivity.java을 시작하기 때문에이

@Override 
    public void onBackPressed() { 
     super.onBackPressed(); 
     this.finish(); 
    } 

로이

@Override 
public void onBackPressed() { 
    Intent goBack = new Intent(EditNote.this, MainActivity.class); 
    startActivity(goBack); 
    finish(); 
} 

변화 거기에 모든

답변

1

첫째.

+0

감사합니다. @ 아이론. 그래, 나는 그것을 간과했다. 어리석은 실수. 그러나'MainActivity.java'가 다시 만들어지면 새로운 ** Example Note **를 만들지 않아야합니까? –

+0

@AkhileshChobey 도움이된다면 대답을 수락 할 수 있습니다. – Ironman

+0

@AkhileshChobey 기꺼이 도와 드리겠습니다. – Ironman

관련 문제