package com.baidu.text1;
import java.io.Serializable;
import com.baidu.text1.R.id;
import com.baidu.text1.R.layout;
import com.bwie.vo.List;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.exception.DbException;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class NewActivity extends Activity implements OnClickListener {
private List list;
private DbUtils db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
// 建库
db = DbUtils.create(NewActivity.this, "1407a");
try {
// 建表
db.createTableIfNotExist(List.class);
} catch (DbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = getIntent();
list = (List) intent.getSerializableExtra("list");
findView();
}
private void findView() {
ImageView img = (ImageView) findViewById(R.id.image);
TextView title = (TextView) findViewById(R.id.text_title);
TextView long_title = (TextView) findViewById(R.id.text_long_title);
TextView intro = (TextView) findViewById(R.id.text_intro);
Button shou = (Button) findViewById(R.id.shou);
Button my = (Button) findViewById(R.id.my);
BitmapUtils bit = new BitmapUtils(NewActivity.this);
bit.display(img, list.getPic());
title.setText(list.getTitle());
long_title.setText(list.getLong_title());
intro.setText(list.getIntro());
shou.setOnClickListener(this);
my.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.shou:
try {
java.util.List<List> find = db.findAll(Selector
.from(List.class).where("title", "=", list.getTitle()));
if (find.size() != 0) {
Toast.makeText(NewActivity.this, "已经收藏过了", 0).show();
return;
} else {
db.save(list);
Toast.makeText(NewActivity.this, "收藏成功", 0).show();
}
} catch (DbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.my:
Intent intent = new Intent(NewActivity.this, ShowActivity.class);
startActivity(intent);
break;
}
}
}