package com.exaple.zhonghe2;

import java.sql.SQLData;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.exaple.Exapa.ExpandBaptwe;
import com.exaple.Exapa.MyHelp;
import com.exaple.netUtil.NetUti;
import com.exaple.vo.Myinfo;
import com.exaple.vo.ShowA;
import com.exaple.vo.Super;
import com.google.gson.Gson;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

public class MainActivity extends Activity {
private String title;

public List<Myinfo> li;
Handler ha = new Handler() {

private Set<String> set_ctitle;
private ArrayList<ShowA> al;

public void handleMessage(android.os.Message msg) {
String ma = (String) msg.obj;
Gson gs = new Gson();
Super fromJson = gs.fromJson(ma, Super.class);
li = fromJson.getInfo();
set_ctitle = new HashSet<String>();
for (Myinfo m : li) {
set_ctitle.add(m.getCtitle());

}

List<String> lis = new ArrayList<String>();
lis.addAll(set_ctitle);
//添加数据库
for (int i = 0; i < lis.size(); i++) {
String set = lis.get(i);
sql.execSQL("insert into user values(null,?)",
new String[] { set });
}

final List<ArrayList<ShowA>> child_list = new ArrayList<ArrayList<ShowA>>();

for (int i = 0; i < lis.size(); i++) {
al = new ArrayList<ShowA>();
for (Myinfo n : li) {
if (n.getCtitle().equals(lis.get(i))) {
ShowA sn = new ShowA();
sn.setCtime(n.getCtime());
sn.setCtitle(n.getCtitle());
sn.setDescript(n.getDescript());
sn.setPicurl(n.getPicurl());
sn.setTitle(n.getTitle());
al.add(sn);

}

}
child_list.add(al);

}
for (int i = 0; i < al.size(); i++) {
String time = al.get(i).getCtime();
String ctitle = al.get(i).getCtitle();
String descrip = al.get(i).getDescript();
String pic = al.get(i).getPicurl();
String title = al.get(i).getTitle();

sql.execSQL("insert into use values(null,?,?,?,?,?)",
new String[] { time, ctitle, descrip, pic, title });
}

ExpandBaptwe ba = new ExpandBaptwe(lis, MainActivity.this,
child_list, text);
exp.setAdapter(ba);

};
};
private EditText edtext;
private Button button;
private ExpandableListView exp;
private String text;

private SQLiteDatabase sql;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtext = (EditText) findViewById(R.id.edtext);
button = (Button) findViewById(R.id.button);
exp = (ExpandableListView) findViewById(R.id.exe);
MyHelp my = new MyHelp(MainActivity.this, "users", null, 1);
sql = my.getWritableDatabase();

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

text = edtext.getText().toString();
new Thread() {
public void run() {
String str = NetUti
.GetJson("http://www.hengboit.com/json/json_search.php?wd="
+ text);
ha.sendMessage(ha.obtainMessage(1, str));

};
}.start();

}
});
exp.setOnChildClickListener(new OnChildClickListener() {

@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Intent ints = new Intent(MainActivity.this, NewActivity.class);
ints.putExtra("name", li.get(childPosition).getCtime());

startActivity(ints);
return true;
}
});
}
}

//适配器

package com.exaple.Exapa;

import java.util.ArrayList;
import java.util.List;

import com.exaple.Exapa.Apater.ViewHodler;
import com.exaple.vo.Myinfo;
import com.exaple.vo.ShowA;
import com.exaple.zhonghe2.MainActivity;
import com.exaple.zhonghe2.NewActivity;
import com.exaple.zhonghe2.R;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.db.sqlite.CursorUtils.FindCacheSequence;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ExpandBaptwe extends BaseExpandableListAdapter {
List<String> lis;

Context co;
List<ArrayList<ShowA>> child_list;
String text;

private SQLiteDatabase sql;

public ExpandBaptwe(List<String> lis, Context co,
List<ArrayList<ShowA>> child_list, String text) {
super();
this.lis = lis;
this.text = text;

this.co = co;
this.child_list = child_list;

MyHelp my = new MyHelp(co, "users", null, 1);
sql = my.getReadableDatabase();

}

@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return lis.size();
}

@Override
public int getChildrenCount(int groupPosition) {
/*String title_group = lis.get(groupPosition);
System.out.println(title_group + "====================");
// 通过向数据库查询出对应的二级列表的信息
Cursor c = sql.rawQuery("select * from use where ctitle = ?",
new String[] { title_group });
System.out.println(lis.get(groupPosition).length());*/
return child_list.get(groupPosition).size();
}

@Override
public Object getGroup(int groupPosition) {
return groupPosition;

}

@Override
public Object getChild(int groupPosition, int childPosition) {
return childPosition;

}

@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}

@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}

@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View view = View.inflate(co,
android.R.layout.simple_expandable_list_item_1, null);
TextView text = (TextView) view.findViewById(android.R.id.text1);

text.setText(lis.get(groupPosition));
return view;
}

@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {

View view_layout = View.inflate(co, R.layout.apater, null);
TextView t1 = (TextView) view_layout.findViewById(R.id.des);
TextView t2 = (TextView) view_layout.findViewById(R.id.time);
ImageView t3 = (ImageView) view_layout.findViewById(R.id.image);
/*
* Cursor c = sql.rawQuery("select * from use where ctitle =?", new
* String[] { lis.get(groupPosition)}); List<Myinfo> list = new
* ArrayList<Myinfo>();
*
* while (c.moveToNext()) { String s =
* c.getString(c.getColumnIndex("title")); list.add(new Myinfo(s));
*
* }
*/

//t1.setText(list.get(childPosition).getTitle());

// List<Myinfo> liss=new ArrayList<Myinfo>();

ShowA a = child_list.get(groupPosition).get(childPosition);
t1.setText(a.getDescript());
t2.setText(a.getTitle());
BitmapUtils bit = new BitmapUtils(co);
bit.display(t3, a.getPicurl());

// 设置字体颜色

if (text != null) {
String str = t2.getText().toString();
int id1 = str.indexOf(text);
if (id1 != -1) {
int end = id1 + text.length();
SpannableStringBuilder builder = new SpannableStringBuilder(str);
ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
builder.setSpan(redSpan, id1, end,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
t2.setText(builder);
}

}

return view_layout;

}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}

}

////数据库

package com.exaple.Exapa;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class MyHelp extends SQLiteOpenHelper{

public MyHelp(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table user(id integer,ctitle)");
db.execSQL("create table use(id integer,ctime,ctitle,descript,picurl,title)");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub

}

}

expandlistview的更多相关文章

  1. Android 实现QQ扩展listview(expandlistview)

    Android 实现QQ扩展listview(expandlistview) <?xml version="1.0" encoding="utf-8"?& ...

  2. cocos2d-x3.1 下实现相似Android下ExpandListView的效果

    在左Android開始有SDK提供ExpandListView的可扩展列表,而在iOS下有很多第三方做好的Demo,这里我是參照iOS下RATreeView这个第三方库实现的. 本文代码:须要在3.1 ...

  3. Android ExpandListView的用法(补上昨天的)(今天自习)

    今天自习写ExpandListView的作业,昨天没写博客就是去写作业去了. 今天来说昨天内容吧! 其实ExpandListView和ListView的用法大同小异. 首先就是创建一个自己的适配器(现 ...

  4. ExpandListView onChildClickListener 失效

    http://stackoverflow.com/questions/11529472/expandablelistview-onchildclicklistener-not-work 首先声明:   ...

  5. 2015最流行的Android组件、工具、框架大全

    Android 是目前最流行的移动操作系统之一. 随着新版本的不断发布, Android的功能也日益强大, 涌现了很多流行的应用程序, 也催生了一大批的优秀的组件. 本文试图将目前流行的组件收集起来以 ...

  6. 站在巨人的肩膀上---重新自定义 android- ExpandableListView 收缩类,实现列表的可收缩扩展

    距离上次更新博客,时隔略长,诸事繁琐,赶在去广州答辩之前,分享下安卓 android 中的一个 列表收缩 类---ExpandableListView 先上效果图: 如果想直接看实现此页面的代码请下滑 ...

  7. Android高手速成--第一部分 个性化控件(View)

    第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...

  8. 据说年薪30万的Android程序员必须知道的帖子

    Android中国开发精英 目前包括: Android开源项目第一篇--个性化控件(View)篇       包括ListView.ActionBar.Menu.ViewPager.Gallery.G ...

  9. 这是一个比较全的Android UI 组件

     Android组件及UI框架大全 原文地址:http://blog.csdn.net/smallnest/article/details/38658593 Android 是目前最流行的移动操作系统 ...

随机推荐

  1. JS全局函数parseInt和parseFloat

    1.parsetInt parseInt(string ,radix)解析一个字符串,并返回一个十进制的整数:该方法是将字符串转成十进制整数 console.log(parseInt("01 ...

  2. Java学习-017-EXCEL 文件读取实例源代码

    众所周知,EXCEL 也是软件测试开发过程中,常用的数据文件导入导出时的类型文件之一,此文主要讲述如何通过 EXCEL 文件中 Sheet 的索引(index)或者 Sheet 名称获取文件中对应 S ...

  3. MFC之向导页、消息框、文件选择、字体、颜色(三)

    属性页对话框的分类 属性页对话框想必大家并不陌生,XP系统中桌面右键点属性,弹出的就是属性页对话框,它通过标签切换各个页面.另外,我们在创建MFC工程时使用的向导对话框也属于属性页对话框,它通过点击“ ...

  4. 终于有人把P2P、P2C、O2O、B2C、B2B、C2C 的区别讲透了

    http://news.mbalib.com/story/88506 P2P.P2C .O2O .B2C.B2B. C2C,每天看着这些常见又陌生的名词,如果有人跟你说让你解释它的含义,金融的小伙伴们 ...

  5. AD834+表面声波滤波器调试小结

    AD834:带宽较宽,300M无压力,但是输出幅度小,当输入2VPPX2VPP的时候最大输出400mVPP.一个特别要注意的地方是输入走线尽量短,敷铜间距至少满足3倍线宽,不然隔直之后还会耦合信号进去 ...

  6. iOS 应用内跳转到appstore里下载

    SKStoreProductViewController类是UIViewController的子类, 如果你对view controller比较熟悉的话,那SKStoreProductViewCont ...

  7. Using dbms_shared_pool.purge to remove a single task from the library cache

    我们都知道可是使用 alter system flush shared_pool 来清除shared pool 信息,当时不能指定清除某个对象.因为在系统繁忙的时侯 使用 alter system f ...

  8. 加州wonders教材扫盲

    加州语文教材主要包含以下内容: 1.主教材Reading/Writing Workshop(读写研讨) 2.拓展教材Literature Anthology(文学选集) 3.延伸阅读材料Leveled ...

  9. sqlserver 2000事务复制问题

    2000现在用的估计不多了,把之前收集的一些复制问题整理发布出来.可能都是些很白很二的问题,但人总是由最初的无知不断成长,不对之处欢迎指正. sqlserver 2000事务复制问题服务器A(发布) ...

  10. rpmdb出问题,重建rpmdb库

    1.备份原库 tar cvzf rpmdb-backup.tar.gz /var/lib/rpm 2.删除rpmdb库 rm -f /var/lib/rpm/__db.00* 3.重建库 rpm -- ...