实现收藏夹

原创 2016年05月30日 12:31:23

话不到说,先上代码
布局activity_main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#f8f8f8" >   
    <TextView
    android:text="网站名称"
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TextView>
    <EditText
    android:text=""
    android:id="@+id/EditTextName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"></EditText>
    <TextView
    android:text="URL"
    android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TextView>
    <EditText
    android:text=""
    android:id="@+id/EditTextURL"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"></EditText>
    <TextView
    android:text="网站描述"
    android:id="@+id/TextView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TextView>
    <EditText
    android:text=""
    android:id="@+id/EditTextDesc"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:height="100px"></EditText>
    <Button
    android:text="添加"
    android:id="@+id/ButtonAdd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></Button>      
</LinearLayout>  

row.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
    android:id="@+id/text0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10px"></TextView>
     <TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10px"></TextView>
     <TextView
    android:id="@+id/text2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10px"></TextView>
     <TextView
    android:id="@+id/text3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10px"/>
</LinearLayout>

DBHelper.java

package com.collect.activity;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.collect.tools.DBHelper;
import com.example.point.R;

public class QueryActivity extends ListActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
       // TODO Auto-generated method stub
       super.onCreate(savedInstanceState);
       this.setTitle("浏览收藏信息");
       final DBHelper helpter = new DBHelper(this);
       Cursor c= helpter.query();
       String[] from = {"_id","name","url","desc"};
       int[] to = {R.id.text0,R.id.text1,R.id.text2,R.id.text3};
       SimpleCursorAdapter adapter = 
        new SimpleCursorAdapter(this, R.layout.row, c, from, to);
       ListView listView = getListView();
       listView.setAdapter(adapter);
       final AlertDialog.Builder builder = new AlertDialog.Builder(this);

       listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
              int arg2, long arg3) {
             // TODO Auto-generated method stub
             final long temp = arg3;
             builder.setMessage("真的要删除吗").
             setPositiveButton("是", new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
               // TODO Auto-generated method stub
               helpter.del((int)temp);
               /*Cursor c = helpter.query();--y有错误
               String[] from = {"_id","naem","url","desc"};
               int[] to ={R.id.text0,R.id.text1,R.id.text2,R.id.text3};*/
               Cursor c= helpter.query();
               String[] from = {"_id","name","url","desc"};
               int[] to = {R.id.text0,R.id.text1,R.id.text2,R.id.text3};
               SimpleCursorAdapter adapter = 
                new SimpleCursorAdapter(getApplicationContext(), R.layout.row, c, from, to);
               ListView listView = getListView();
               listView.setAdapter(adapter);
              }
             }).setNegativeButton("否", new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
               // TODO Auto-generated method stub 
              }
             });
             AlertDialog ad  = builder.create();
             ad.show();
            }   
       });
      }
}

MainActivity.java

package com.collect.activity;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.collect.tools.DBHelper;
import com.example.point.R;

public class MainActivity extends Activity {
     private EditText et1,et2,et3;
     private Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.setTitle("添加收藏信息");

        DBHelper helper = new DBHelper(getApplicationContext());
        SQLiteDatabase db=helper.getWritableDatabase();
        db.close();

        et1 = (EditText)findViewById(R.id.EditTextName);
        et2 = (EditText)findViewById(R.id.EditTextURL);
        et3 = (EditText)findViewById(R.id.EditTextDesc);
        b1 = (Button)findViewById(R.id.ButtonAdd);
        b1.setOnClickListener(new OnClickListener() {   
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                String name = et1.getText().toString();
                String url = et2.getText().toString();
                String desc = et3.getText().toString();
                ContentValues values = new ContentValues();
                values.put("name", name);
                values.put("url", url);
                values.put("desc", desc);
                DBHelper helper = new DBHelper(getApplicationContext());
                helper.insert(values);
                Intent intent = new Intent(MainActivity.this, QueryActivity.class);
                startActivity(intent);   
       }});  
    }
}

QueryActivity.java

package com.collect.activity;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.collect.tools.DBHelper;
import com.example.point.R;

public class QueryActivity extends ListActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
       // TODO Auto-generated method stub
       super.onCreate(savedInstanceState);
       this.setTitle("浏览收藏信息");
       final DBHelper helpter = new DBHelper(this);
       Cursor c= helpter.query();
       String[] from = {"_id","name","url","desc"};
       int[] to = {R.id.text0,R.id.text1,R.id.text2,R.id.text3};
       SimpleCursorAdapter adapter = 
        new SimpleCursorAdapter(this, R.layout.row, c, from, to);
       ListView listView = getListView();
       listView.setAdapter(adapter);
       final AlertDialog.Builder builder = new AlertDialog.Builder(this);

       listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
              int arg2, long arg3) {
             // TODO Auto-generated method stub
             final long temp = arg3;
             builder.setMessage("真的要删除吗").
             setPositiveButton("是", new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
               // TODO Auto-generated method stub
               helpter.del((int)temp);
               /*Cursor c = helpter.query();--y有错误
               String[] from = {"_id","naem","url","desc"};
               int[] to ={R.id.text0,R.id.text1,R.id.text2,R.id.text3};*/
               Cursor c= helpter.query();
               String[] from = {"_id","name","url","desc"};
               int[] to = {R.id.text0,R.id.text1,R.id.text2,R.id.text3};
               SimpleCursorAdapter adapter = 
                new SimpleCursorAdapter(getApplicationContext(), R.layout.row, c, from, to);
               ListView listView = getListView();
               listView.setAdapter(adapter);
              }
             }).setNegativeButton("否", new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
               // TODO Auto-generated method stub 
              }
             });
             AlertDialog ad  = builder.create();
             ad.show();
            }   
       });
      }
}

项目文件目录
这里写图片描述
效果图
这里写图片描述
这里写图片描述
这里写图片描述

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

全站ajax.net实现的在线99收藏夹,大家共享!

====================================================== 注:本文源代码点此下载 =============================...

web开发设为首页、添加到收藏夹实现方法

web开发设为首页、添加到收藏夹实现方法

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

FireFox导入导出Cookies和收藏夹的方法

FireFox是一个常用的浏览器,扩展插件众多,和IE相比有很多优点,不过有些细小的地方似乎考虑的不太好,比如用户经常会碰到系统重新安装等问题,这就需要导入导出FireFox浏览器的Cookies和收...

开发人员一定要加入收藏夹的网站

http://www.gotapi.com/  语言:英语  简介:HTML,CSS,XPATH,XSL,JAVASCRIPT等API的查询网站。 http://www.w3schools.co...

资源收藏夹

个人收藏的编程学习网站、技术博客、技术社区、竞赛、学术论文、公众号、书籍等

将猎豹浏览器的收藏夹转移到Firefox的书签

本人之前一直使用Chrome,后来因为常常重装系统,Chrome的同步功能不能直接使用。这个很蛋疼,就换用了猎豹浏览器,用了很长时间,但是近期一直在做前端发开,Firefox的开发者功能当然不用说是最...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)