80,493
社区成员
发帖
与我相关
我的任务
分享
public class SetScene extends ListActivity implements OnClickListener {
private MyAdapter adapter = null;
private Button back, but_ci_del, but_ci_s, but_ci_select;
private ArrayList<Map<String, Object>> array;
private Context context;
private TextView tv_title, tv_thing;
private ListViewInterceptor tlv;
private String schemename, Sname;
private static String[] SchemeName = null;
protected String Snames = "";
private Map<String, Integer> iamgel = new HashMap<String, Integer>();
// 启动
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.setscene);
context = SetScene.this;
// 获取数据
String sid = SaveSharedPreferences.getSceneMode(SetScene.this);
// 通过sid 查询m
MenuSchemeDao msd = new MenuSchemeDao(context);
// 需要显示的 场景的id
Log.i("csxm", msd.getMenuids(sid));
tv_title = (TextView) findViewById(R.id.tv_titles);
but_ci_del = (Button) findViewById(R.id.but_ci_del);
but_ci_s = (Button) findViewById(R.id.but_ci_s);
but_ci_select = (Button) findViewById(R.id.but_ci_select);
tv_thing = (TextView) findViewById(R.id.tv_thing);
but_ci_del.setOnClickListener(this);
but_ci_s.setOnClickListener(this);
but_ci_select.setOnClickListener(this);
// 通过sid 查询m
MySqlHelper sql = new MySqlHelper(context);
Cursor name = sql.fetchMenuSchemeitem(sid);
schemename = name.getString(name.getColumnIndex("schemename"));
System.out.println(schemename);
tv_title.setText(schemename);
name.close();
sql.close();
array = getData();
adapter = new MyAdapter(array);
setListAdapter(adapter);
back = (Button) findViewById(R.id.back);
back.setOnClickListener(this);
tlv = (ListViewInterceptor) getListView();
tlv.setDropListener(onDrop);
tlv.getAdapter();
tlv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Class<Scenese> intclass = Scenese.class;
Intent localIntent = new Intent();
Bundle localBundle = new Bundle();
String titles;
String edaView;
array.get(arg2);
titles = (String) array.get(arg2).get("title");
edaView = "您好,我正在" + titles + "中,不方便接听电话,稍后给您回电!";
localBundle.putString("titles", "" + titles);
localBundle.putString("edaView", edaView);
// 判断然后跳转
localIntent.putExtras(localBundle);
localIntent.setClass(SetScene.this, intclass);
startActivity(localIntent);
}
});
}
// 滑动特效
private ListViewInterceptor.DropListener onDrop = new ListViewInterceptor.DropListener() {
public void drop(int from, int to) {
Map<String, Object> item = adapter.getItem(from);
adapter.remove(item);
adapter.insert(item, to);
for (int i = 0; i < adapter.getCount(); i++) {
adapter.getItem(i).put("flag", "0");
array.set(i, adapter.getItem(i));
array.get(3).put("flag", "1");
Log.e("a", array.get(i).get("flag").toString() + ";" + to + ";"
+ array.get(i).get("title"));
}
// 让第四行 显示分割
adapter.chargeProgress(3, array.get(3));
Log.i("a", array.get(3).get("flag").toString() + ";" + to + ";"
+ array.get(3).get("title"));
}
};
class MyAdapter extends ArrayAdapter<Map<String, Object>> {
ArrayList<Map<String, Object>> list;
MyAdapter(ArrayList<Map<String, Object>> array) {
super(SetScene.this, R.layout.setsceneitem, array);
list = array;
}
public ArrayList<Map<String, Object>> getList() {
return list;
}
// 改变进度,postion就是要改的那个进度
public void chargeProgress(int postion, Map<String, Object> detail) {
list.set(postion, detail);
System.out.println("charged:" + detail.get("flag"));
notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.setsceneitem, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.tv_thing);
ImageView imageView = (ImageView) row.findViewById(R.id.iv_icon);
RelativeLayout line = (RelativeLayout) row.findViewById(R.id.line);
Map<String, Object> detail = list.get(position);
label.setText(detail.get("title").toString());
imageView.setImageResource(Integer.valueOf(detail.get("img")
.toString()));
if (detail.get("flag").toString() == "1")
line.setVisibility(0);
else
line.setVisibility(8);
row.postInvalidate();
return (row);
}
}
private ArrayList<Map<String, Object>> getData() {
ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
MenuSchemeDao menudao = new MenuSchemeDao(context);
Cursor cursor = menudao.getMenuid(schemename);
iamgel.put("icon_meeting.png", Integer.valueOf(R.drawable.icon_meeting));
iamgel.put("icon_nocall.png", Integer.valueOf(R.drawable.icon_nocall));
iamgel.put("icon_blacklist.png",
Integer.valueOf(R.drawable.icon_blacklist));
iamgel.put("icon_callmsg.png", Integer.valueOf(R.drawable.icon_callmsg));
iamgel.put("icon_car.png", Integer.valueOf(R.drawable.icon_car));
iamgel.put("icon_sport.png", Integer.valueOf(R.drawable.icon_sport));
iamgel.put("icon_rest.png", Integer.valueOf(R.drawable.icon_rest));
iamgel.put("icon_class.png", Integer.valueOf(R.drawable.icon_class));
iamgel.put("icon_study.png", Integer.valueOf(R.drawable.icon_study));
iamgel.put("icon_nobattery.png",
Integer.valueOf(R.drawable.icon_nobattery));
iamgel.put("icon_travel.png", Integer.valueOf(R.drawable.icon_travel));
iamgel.put("icon_train.png", Integer.valueOf(R.drawable.icon_train));
iamgel.put("scene_meeting.png",
Integer.valueOf(R.drawable.scene_meeting));
iamgel.put("scene_nocall.png", Integer.valueOf(R.drawable.scene_nocall));
iamgel.put("scene_blacklist.png",
Integer.valueOf(R.drawable.scene_blacklist));
iamgel.put("scene_callmsg.png",
Integer.valueOf(R.drawable.scene_callmsg));
iamgel.put("scene_car.png", Integer.valueOf(R.drawable.scene_car));
iamgel.put("scene_sport.png", Integer.valueOf(R.drawable.scene_sport));
iamgel.put("scene_rest.png", Integer.valueOf(R.drawable.scene_rest));
iamgel.put("scene_class.png", Integer.valueOf(R.drawable.scene_class));
iamgel.put("scene_study.png", Integer.valueOf(R.drawable.scene_study));
iamgel.put("scene_nobattery.png",
Integer.valueOf(R.drawable.scene_nobattery));
iamgel.put("scene_travel.png", Integer.valueOf(R.drawable.scene_travel));
iamgel.put("scene_train.png", Integer.valueOf(R.drawable.scene_train));
while (cursor.moveToNext()) {
SetSceneInfo info = new SetSceneInfo();
info.menuids = cursor.getString(cursor.getColumnIndex("menuids"));
String menuids = info.getMenuids();
String[] ids = menuids.split(",");
for (int i = 0; i < ids.length; i++) {
int idn = Integer.parseInt(ids[i]);
Cursor mcursor = menudao.getMenuName(ids[i]);
info.schemename = mcursor.getString(mcursor
.getColumnIndex("menuname"));
info.image = mcursor.getString(mcursor
.getColumnIndex("iconfile"));
String imname = info.getImage();
Sname = info.getSchemename();
Snames += Sname + ",";
SchemeName = Snames.split(",");
map = new HashMap<String, Object>();
map.put("title", SchemeName[i]);
map.put("img", iamgel.get(imname));
if (i == 3) {
map.put("flag", "1");
} else {
map.put("flag", "0");
}
Log.d("tag", SchemeName[i]);
list.add(map);
mcursor.close();
}
}
cursor.close();
menudao.close();
return list;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.back:
finish();
break;
case R.id.but_ci_del:
finish();
break;
case R.id.but_ci_s:
finish();
break;
case R.id.but_ci_select:
finish();
break;
}
}
}

标记下
看下有没有更好的办法
有会的人么。。。