gpt4 book ai didi

java - 切片 ListView

转载 作者:行者123 更新时间:2023-11-29 05:49:40 32 4
gpt4 key购买 nike

有人能给我一个关于如何分割 ListView 的例子吗?我正在使用 SimpleCursorAdapter 在 ListView 中显示数据..

我的代码是这样的。

private WordDbAdapter dbHelper;
private SimpleCursorAdapter dataAdapter;

这是 onCreate() 方法的代码。

    dbHelper = new WordDbAdapter(this);
dbHelper.open();

//Clean all data
dbHelper.deleteAllWords();
//Add some data
dbHelper.insertSomeWords();

//Generate ListView from SQLite Database
displayListView();

这是 onCreate 方法之外的代码。

@SuppressWarnings("deprecation")
private void displayListView() {


Cursor cursor = dbHelper.fetchAllWords();

// The desired columns to be bound
String[] columns = new String[] {
WordDbAdapter.KEY_WORD,

};

// the XML defined views which the data will be bound to
int[] to = new int[] {

R.id.Word,

};

// create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(
this, R.layout.word_info,
cursor,
columns,
to
);

ListView listView = (ListView) findViewById(R.id.Diclist);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);


listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
// Get the cursor, positioned to the corresponding row in the result set
Cursor cursor = (Cursor) listView.getItemAtPosition(position);


// Get the word name from this row in the database.
String wordSelected =
cursor.getString(cursor.getColumnIndexOrThrow("word"));

String wordSyllabication =
cursor.getString(cursor.getColumnIndexOrThrow("syllabication"));
String wordPartofSpeech =
cursor.getString(cursor.getColumnIndexOrThrow("partofspeech"));
String wordMeaning =
cursor.getString(cursor.getColumnIndexOrThrow("meaning"));

EditText TextDic = (EditText) findViewById(R.id.TextDic);
TextDic.setText(wordSelected);


Toast.makeText(getApplicationContext(),
wordSyllabication + "\n" + wordPartofSpeech + "\n" + wordMeaning , Toast.LENGTH_SHORT).show();

}
});

最佳答案

我在这个 blog 上找到了分段 ListView 的一个很好的例子.它是通过使用 ArrayAdapter 完成的,但您可以看到这个概念并尝试相应地操作代码以使其与 SimpleCursorAdapter 一起工作。希望对您有所帮助!!

关于java - 切片 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14411379/

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