public class GetContentTitle extends Activity implements OnClickListener { List<Person> persons; ImageButton btn_back, ib_share, ib_faver,ib_faver1; TextView hTextView, tTextView, tcTextView; String h_name; String content_name; String content_tittle_name; private boolean flag = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fenxiang11); findView(); Bundle bundle = getIntent().getExtras(); if (bundle != null) { h_name = bundle.getString("head_name"); String t_name = bundle.getString("t_name"); content_name = bundle.getString("content_name"); content_tittle_name = bundle.getString("content_tittle_name"); System.out.println("************************"); // SaveMyDreamData smdd = new SaveMyDreamData(); // smdd.open(GetContentTitle.this); // smdd.getCount("幸运的事情即将发生。可以尝到美昧可口的咖啡、得到电影招待券等等。你将不觉莞尔一笑。"); // smdd.close(); System.out.println("close database"); if (t_name != null) { persons = MyPullxml.getcontent_tittle_content( GetContentTitle.this, h_name, t_name, content_name, content_tittle_name); tcTextView.setText(persons.get(0).getC_t_content()); Log.i("name",persons.get(0).getC_t_content()); SaveMyDreamData smdd = new SaveMyDreamData(); smdd.open(GetContentTitle.this); flag = smdd.getCount(persons.get(0).getC_t_content()); smdd.close(); //System.out.println("--------------"+persons.get(0).getC_t_content()); } else { tcTextView.setText(bundle.getString("content_tittle_content")); ib_faver.setVisibility(View.GONE); ib_faver1.setVisibility(View.VISIBLE); } hTextView.setText(h_name); tTextView.setText(content_name); } if(flag){ ib_faver.setVisibility(View.GONE); ib_faver1.setVisibility(View.VISIBLE); } } private void findView() { Navigation.AddViewListener(GetContentTitle.this, 0); hTextView = (TextView) findViewById(R.id.c_tv_content); tTextView = (TextView) findViewById(R.id.c_lv_categories); tcTextView = (TextView) findViewById(R.id.c_lv_categories1); btn_back = (ImageButton) findViewById(R.id.c_ib_back2); btn_back.setOnClickListener(this); ib_faver = (ImageButton) findViewById(R.id.getContentTitle_ib_faver); ib_faver.setOnClickListener(this); ib_faver1 = (ImageButton)findViewById(R.id.getContentTitle_ib_faver1); ib_faver1.setOnClickListener(this); ib_share = (ImageButton) findViewById(R.id.getContentTitle_ib_share); ib_share.setOnClickListener(this); } public void onClick(View v) { if (v.equals(btn_back)) { finish(); } else if (v.equals(ib_faver)) { returnDialog(); } else if (v.equals(ib_share)) { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("content", tcTextView.getText().toString()); bundle.putString("content_tittle_name", content_tittle_name); intent.putExtras(bundle); intent.setClass(GetContentTitle.this, Share.class); startActivity(intent); }else if(v.equals(ib_faver1)){ repeatDialog(); } } public void returnDialog() { new AlertDialog.Builder(GetContentTitle.this) .setTitle("收藏提示").setMessage("让我收藏你的梦吧!") .setPositiveButton("好的", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SaveMyDreamData saveMyDreamData = new SaveMyDreamData(); saveMyDreamData.open(GetContentTitle.this); saveMyDreamData.insert(h_name, content_name, content_tittle_name, tcTextView.getText() .toString()); /*ib_faver.setBackgroundDrawable(getResources() .getDrawable(R.drawable.faver1));{ }*/ ib_faver.setVisibility(View.GONE); //flag = true; ib_faver1.setVisibility(View.VISIBLE); saveMyDreamData.close(); } }) .setNegativeButton("不要了,谢谢", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).show(); } public void repeatDialog(){ new AlertDialog.Builder(GetContentTitle.this).setTitle("已经加入过收藏"). setMessage("我已经在你的收藏夹了!").setPositiveButton("我知道了", null).show(); } } 好好学习