gpt4 book ai didi

java - 使 ListView 项目可点击出现问题

转载 作者:行者123 更新时间:2023-11-29 00:48:35 24 4
gpt4 key购买 nike

My Listview 获取保存在本地数据库中的信息并显示信息。我正在改变单击 ListView 项时发生的情况。我想删除它们,有人可以在使用我的代码时帮助我解决这个问题吗?在此先感谢您!

public class Notepad extends ListActivity {
public static final int INSERT_ID = Menu.FIRST;
EditText notes;
Button add;
ListView lv;
String currentDateTimeString = DateFormat.getDateInstance().format(
new Date());

private NotesDbAdapter mDbHelper;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notepad_list);
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
fillData();
Button add = (Button) findViewById(R.id.addNote);
// ListView lv = (ListView) findViewById(R.id.list);

add.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

createNote();

}
});
// lv.setOnItemClickListener(new OnItemClickListener() {
//
// public void onItemClick(AdapterView<?> parent, View view,
// int position, long id) {
// // When clicked, show a toast with the TextView text
//
// try {
// Toast.makeText(getApplicationContext(),
// ((TextView) view).getText(), Toast.LENGTH_SHORT)
// .show();
//
// } catch (ClassCastException e) {
// Toast.makeText(getApplicationContext(), "Error",
// Toast.LENGTH_SHORT).show();
// }
//
// };
//
// });
}

private void createNote() {
EditText notes = (EditText) findViewById(R.id.note);
String noteName = notes.getText().toString();
Calendar c = Calendar.getInstance();
int seconds = c.get(Calendar.SECOND);
int minutes = c.get(Calendar.MINUTE);
int hour = c.get(Calendar.HOUR);
mDbHelper.createNote(noteName + " Entered at " + hour + ":" + minutes
+ ":" + seconds, "");

fillData();
}

private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = mDbHelper.fetchAllNotes();
startManagingCursor(c);

String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
int[] to = new int[] { R.id.text1 };

// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
}

我的 ListView :

   <ListView
android:id="@id/android:list"
android:layout_width="wrap_content"
android:layout_height="402dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/note" >
</ListView>

最佳答案

onListItemClick 你得到了位置并从动态数组( vector 或列表)中删除它就像vector.remove(position);。如果你想从数据库中删除它,也从数据库中删除。之后你只需写.....

adapter.notifyDataSetChanged();

关于java - 使 ListView 项目可点击出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9479506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com