Android添加书签(二)
运行结果:
Bookmarker.java:
Java代码
package com.iaiai;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInte易做图ce;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
/**
*
* <p>
* Title: Bookmarker.java
* </p>
* <p>
* E-Mail: 176291935@qq.com
* </p>
* <p>
* QQ: 176291935
* </p>
* <p>
* Http: iaiai.iteye.com
* </p>
* <p>
* Create time: 2011-8-29
* </p>
*
* @author 丸子
* @version 0.0.1
*/
public class Bookmarker extends Activity implements OnItemClickListener,
OnClickListener {
/** Called when the activity is first created. */
private ListView mListView;
private BookmarkAdapter bookmarkAdapter;
private ImageButton upButton;
private ImageButton downButton;
private ImageButton deleteButton;
private ImageButton launchButton;
private ImageButton topButton;
private ImageButton bottomButton;
private static final int DIALOG_YES_NO_MESSAGE = 1;
private static final int DIALOG_WELCOME = 2;
private int currentPos = -1;
private static final String PREFS_NAME = "BookmarkerPrefs";
private static final String LAUNCHED_KEY = "LAUNCHED";
private static final int MENU_ABOUT = 0;
private static final int MENU_ADD = 1;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ContentValues inputValue = new ContentValues();
inputValue.put(android.provider.Browser.BookmarkColumns.BOOKMARK, 1);
inputValue.put(android.provider.Browser.BookmarkColumns.TITLE, "丸子");
inputValue.put(android.provider.Browser.BookmarkColumns.URL, "http://iaiai.iteye.com");
ContentResolver cr = getContentResolver();
Uri uri = cr.insert(android.provider.Browser.BOOKMARKS_URI, inputValue);
bookmarkAdapter = new BookmarkAdapter(this, "");// new
// ArrayAdapter<Bookmark>(this,
// android.R.layout.易做图_list_item_single_choice,bookmarks);
mListView = ((ListView) findViewById(R.id.mylistview));
mListView.setAdapter(bookmarkAdapter);
mListView.setOnItemClickListener(this);
upButton = (ImageButton) findViewById(R.id.upbutton);
downButton = (ImageButton) findViewById(R.id.downbutton);
deleteButton = (ImageButton) findViewById(R.id.deletebutton);
launchButton = (ImageButton) findViewById(R.id.launchbutton);
topButton = (ImageButton) findViewById(R.id.topbutton);
bottomButton = (ImageButton) findViewById(R.id.bottombutton);
upButton.setOnClickListener(this);
downButton.setOnClickListener(this);
deleteButton.setOnClickListener(this);
launchButton.setOnClickListener(this);
topButton.setOnClickListener(this);
bottomButton.setOnClickListener(this);
// if we have some bookmarks select the first and start everything
if (bookmarkAdapter.getCount() > 0) {
bookmarkAdapter.initialiseAllRows();
currentPos = 0;
bookmarkAdapter.setSelected(currentPos);
}
// Make sure the welcome message only appears on first launch
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings != null) {
boolean launchedPreviously = settings.getBoolean(LAUNCHED_KEY,
 
补充:移动开发 , Android ,