private void bookRename(final File file) { final EditText etNewName = new EditText(this); etNewName.setText(BookUtil.getFileName(file)); new AlertDialog.Builder(this) .setTitle("重命名") .setView(etNewName) .setPositiveButton( "确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String oldName = file.getAbsolutePath().toString(); String newName = oldName.substring(0, oldName.lastIndexOf("/") + 1) + etNewName.getText().toString() + "." + BookUtil.getFileType(file); file.renameTo(new File(newName)); openDb(); db.execSQL("insert into book_list(bookname)values('" + newName + "');"); db.delete("book_list", "bookname = ?", new String[] {oldName}); initBookList(); bookAdapter.notifyDataSetChanged(); } }) .setNegativeButton("取消", null) .show(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { Context context = getApplicationContext(); LinearLayout view = new LinearLayout(context); ImageView img = new ImageView(context); img.setImageResource(R.drawable.book); TextView textView = new TextView(context); textView.setText(BookUtil.getFileName(bookList.get(position))); textView.setGravity(Gravity.CENTER); textView.setTextColor(getResources().getColor(R.color.black)); view.setOrientation(LinearLayout.VERTICAL); view.addView(img, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); view.addView(textView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); return view; }