sách gpt4 ai đã đi

java - 如何将数据从sqlite缓存到listview?

In lại 作者:行者123 更新时间:2023-12-01 05:20:39 27 4
mua khóa gpt4 Nike

大家好,我有一个 Activity ,它扩展了 ListActivity 并显示一个从我的 SQLite DB 表填充的 ListView 。

我的 ListView 中的每个条目都有相同的背景文件作为我的 GUI 设计的一部分。问题是我的 ListView 中的滚动非常滞后。我认为这是因为每个 ListView 条目都是“动态”创建的,这会导致滞后。

您能否查看我的代码并告诉我如何缓存它以获得更好的结果?或者也许还有其他解决方案?

Mã số:

package android.GUI;


public class Shifts extends ListActivity implements OnClickListener,
SimpleGestureListener {

private Typeface tf = Entry.tf, tf2 = Entry.tf2;
public static int count = 1;
int dbHourTime = 0;
private SimpleGestureFilter detector;
public static DBAdapter DB;
public static Cursor cursor;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.shifts);

detector = new SimpleGestureFilter(this, this);

DB = new DBAdapter(this);
DB.open();

String[] columns = new String[] { DB.KEY_DATE, DB.KEY_HOURS,
DB.KEY_DAY, DB.KEY_ROWID, DB.KEY_START, DB.KEY_END };
int[] to = new int[] { R.id.dateDisp, R.id.shiftDisp, R.id.day,
R.id.rawId, R.id.start, R.id.finish };
new cursorLoad().execute("this");

TextView SF = (TextView) findViewById(R.id.total);
SF.setTypeface(tf);

TextView sum = (TextView) findViewById(R.id.sum);
sum.setTypeface(tf);

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.list_entry, cursor, columns, to);
this.setListAdapter(mAdapter);

}

@Ghi đè
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.view_shifts_menu, menu);
trả về giá trị đúng;
}

@Ghi đè
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.back:

finish();
trả về giá trị đúng;
case R.id.clear:
DBAdapter DB = new DBAdapter(this);
DB.open();
DB.deleteAll();
startActivity(getIntent());
finish();

trả về giá trị đúng;
mặc định:
return super.onOptionsItemSelected(item);
}
}

@Ghi đè
public void onClick(View v) {
// TODO Phương thức tự động tạo stub

}

@Ghi đè
public void onSwipe(int direction) {

Intent intent = new Intent();

switch (direction) {

case SimpleGestureFilter.SWIPE_RIGHT:

intent.setClass(this, Main.class);
startActivity(intent);
phá vỡ;
case SimpleGestureFilter.SWIPE_LEFT:

intent.setClass(this, Entry.class);
startActivity(intent);
phá vỡ;
case SimpleGestureFilter.SWIPE_DOWN:

phá vỡ;
case SimpleGestureFilter.SWIPE_UP:

phá vỡ;
}

}

@Ghi đè
public boolean dispatchTouchEvent(MotionEvent me) {
this.detector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}

@Ghi đè
public void onDoubleTap() {
// TODO Phương thức tự động tạo stub

}

public class cursorLoad extends AsyncTask {

@Ghi đè
protected String doInBackground(String... params) {
// TODO Phương thức tự động tạo stub

cursor = DB.getAllShifts();
startManagingCursor(cursor);
cursor.moveToLast();
count = cursor.getPosition();
int g = count;

cursor.moveToNext();
trả về giá trị null;
}

}

}

1 Câu trả lời

最后我需要的是 ViewHolder 类以及 getView\bindView。

关于java - 如何将数据从sqlite缓存到listview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10473659/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com