안녕하세요. SQLite 데이터베이스에서 연락처를 추가하는 ListFragment를 사용하고 있습니다. ListFragment를 새로 고치고 싶지만 작동하지 않습니다.Android : ListFragment가 새로 고침되지 않습니다.
//Handle OnClick events on ActionBar items
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle item selection
switch (item.getItemId()) {
case R.id.menu_add:
Toast.makeText(getActivity(), "Click", Toast.LENGTH_SHORT).show();
LayoutInflater factory = LayoutInflater.from(getActivity());
//textEntryView is an Layout XML file containing text field to display in alert dialog
textEntryView = factory.inflate(R.layout.dialog_add_room, null);
//get the control from the layout
enter_room = (EditText) textEntryView.findViewById(R.id.enter_room);
//create Dialog
final AlertDialog.Builder alert1 = new AlertDialog.Builder(getActivity());
//configure dialog
alert1.setTitle("Raum hinzufügen:").setView(textEntryView)
.setPositiveButton("Hinzufügen",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
String roomname = enter_room.getText().toString();
Log.d("Insert: ", "Inserting ..");
dbHandler.addContact(new Contact(roomname, "0"));
adapter.notifyDataSetChanged();
}
}).setNegativeButton("Abbrechen",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
//cancel dialog
}
});
alert1.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
에서 OnCreate() 메소드 내부에 정의 된 어댑터 :
이
는 ListFragment에 연락처를 추가하는 액션 바의 항목을 클릭 후에 AlertDialog를 표시하는 내 조각 내부의 코드@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//display ActionBar items
setHasOptionsMenu(true);
//database
dbHandler = new DatabaseHandler(getActivity());
//get all contacts
contacts = dbHandler.getAllContacts();
adapter = new ArrayAdapter<Contact>(getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1, contacts);
adapter.setNotifyOnChange(true);
//show all contacts in the ListFragment
setListAdapter(adapter);
}
무엇이 문제인가?
자세한 답변을 주셔서 감사합니다. ContentProvider를 구현하려고합니다. 이것은 내 눈에서 최고의 솔루션처럼 보입니다. ContentProvider를 사용하지 않으므로 구현하기까지 다소 시간이 걸릴 것입니다. –