乐学成语——显示每个成语的详细信息
2016-06-04 11:29
330 查看
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() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.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; @Override protected 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() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { // TODO Auto-generated method stub Animal 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 stub animalDao=AnimalDao.getInstance(this); animalList=animalDao.getAllAnimals(); } @Override public 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>现在可以运行一下,界面如下
相关文章推荐
- Java 程序员学习中各阶段的建议
- Hello Word!
- 软件工程——个人最终总结
- 学习进度条 第十四周
- Android中解析JSON格式数据常见方法合集
- JAVA016--反射
- Java目前需要学些的内容(转)
- android捕获ListView中每个item点击事件
- 对“移动产品经理”的理解
- cout << string 编译错误
- iOS 【UIKit-UITableViewCell的重用方式&static】
- C 语言编程技巧
- 利用AsyncTast实现图片下载
- 截包与重放是个技术活
- SpringMVC+Mybatis框架整合源码
- 2016年工作中遇到的问题21-30
- Android libpng error: Not a PNG file错误解决
- 设计模式之代理模式
- C语言内存管理函数
- 定时任务 Crontab命令 详解