乐学成语——显示每个成语的详细信息
来源:互联网 发布:阮一峰 javascript 编辑:程序博客网 时间:2024/03/29 04:31
1.新建布局文件dialog_infos.xml。
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_ling" android:orientation="vertical" > <TextView android:id="@+id/tvIdiomInfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Medium Text" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout> </ScrollView></span>
2.新建DialogUtil类。
<span style="font-size:18px;">package com.edu.happyidiom.util;import com.example.happyidiom.R;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.view.LayoutInflater;import android.view.View;import android.widget.TextView;public class DialogUtil {public static void showDialog(String result,Context context){AlertDialog.Builder builder=new AlertDialog.Builder(context);LayoutInflater layoutInflater=LayoutInflater.from(context);View view=layoutInflater.inflate(R.layout.dialog_infos, null);builder.setView(view);TextView tvIdiomInfo=(TextView) view.findViewById(R.id.tvIdiomInfo);tvIdiomInfo.setText(result);builder.setPositiveButton("确定", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubdialog.dismiss();}});builder.create().show();}</span>
3.修改StudyAnimalActivity的点击事件。
<span style="font-size:18px;">package com.example.happyidiom;import java.util.List;import com.edu.happyidiom.adapter.AnimalAdapter;import com.edu.happyidiom.dao.AnimalDao;import com.edu.happyidiom.entity.Animal;import com.edu.happyidiom.util.DialogUtil;import android.os.Bundle;import android.app.Activity;import android.util.Log;import android.view.Menu;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ListView;public class StudyAnimalActivity extends Activity {private List<Animal> animalList;private AnimalDao animalDao;private ListView lvAnimalList;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_study_animal);initAnimals();lvAnimalList=(ListView) findViewById(R.id.lvAnimalList); AnimalAdapter animalAdapter=new AnimalAdapter(this, R.layout.animal_item, animalList); lvAnimalList.setAdapter(animalAdapter); lvAnimalList.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> adapterView, View view, int position,long id) {// TODO Auto-generated method stubAnimal animal=animalList.get(position);String result=animal.getName()+"\n"+animal.getPronounce()+"\n【解释】:"+animal.getExplain()+"\n【近义词】:"+animal.getHomoionym()+"\n【反义词】:"+animal.getAutonym()+"\n【来源】:"+animal.getDerivation()+"\n【示例】:"+animal.getExamples();DialogUtil.showDialog(result, StudyAnimalActivity.this);}});}private void initAnimals() {// TODO Auto-generated method stubanimalDao=AnimalDao.getInstance(this);animalList=animalDao.getAllAnimals();}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.study_animal, menu);return true;}}</span>现在可以运行一下,界面如下
0 0
- 乐学成语——显示每个成语的详细信息
- 乐学成语——显示每条成语的详细信息
- 6.乐学成语----------显示每条成语的详细信息
- 乐学成语实现之五:显示每条成语的详细信息
- 乐学成语——显示所有动物类成语的列表
- 乐学成语——显示所有动物类成语的列表
- 个人完成案例之乐学成语(显示所有动物类成语的列表和每条成语的详细信息)
- 乐学成语(成语分类列表显示)
- 乐学成语——显示学习列表
- 乐学成语——显示主界面
- 乐学成语——显示学习列表
- 5.乐学成语-----------显示动物类成语列表
- 乐学成语——数据库操作
- 乐学成语——导入篇
- 乐学成语——第一部分
- 乐学成语——完整实现
- 乐学成语——第二部分
- 乐学成语——第三部分
- JVM调优系列(三)——GC垃圾回收机制
- Hello Word!
- 定制日志轮替
- iOS 【UIKit-Interface Builder(面试)】
- 【数据结构】HashTable原理及实现学习总结
- 乐学成语——显示每个成语的详细信息
- 计算机图形学基础(二) 三维变换和四元数
- 贴片式元器件焊接方法
- 怎样快糙猛的开始搞Kaggle比赛
- ajax请求ashx跨域问题解决办法
- Thinkphp3.2整合类库--(tcpdf示例)
- ExpandableTextView
- Linux中的configure、pkg-config、pkg_config_path
- Java Comparable 和Comparator接口的使用及区别