这个是飞信群发界面的源代码:SendPerson.java,通过TabHost控件实现个人和飞信群发组的切换。
package com.huangcheng.FetionSend; import com.huangcheng.mainFrame.R; import Android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; public class SendPerson extends TabActivity implements OnTabChangeListener { private TabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.sendperson); mTabHost = getTabHost(); mTabHost.setOnTabChangedListener(this); setupTab1(); setupTab2(); mTabHost.setCurrentTab(0); } private void setupTab2() { // TODO Auto-generated method stub Intent intent = new Intent(); intent.setClass(this, SendGroup.class); mTabHost.addTab(mTabHost .newTabSpec("SendGroup") .setIndicator("飞信群组群发", getResources().getDrawable(R.drawable.qun)) .setContent(intent)); } private void setupTab1() { // TODO Auto-generated method stub Intent intent = new Intent(); intent.setClass(this, SendSelected.class); mTabHost.addTab(mTabHost .newTabSpec("SendSelected") .setIndicator("飞信选择群发", getResources().getDrawable(R.drawable.one)) .setContent(intent)); } public void onTabChanged(String tabId) { // TODO Auto-generated method stub Activity activity = getLocalActivityManager().getActivity(tabId); if (activity != null) { activity.onWindowFocusChanged(true); } } }
这个是给个人发飞信的界面,以及添加联系人组成飞信群组:SendSelected.java
package com.huangcheng.FetionSend; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.huangcheng.mainFrame.MyAdapter; import com.huangcheng.mainFrame.R; import com.huangcheng.mainFrame.MyAdapter.ViewHolder; import com.huangcheng.sql.GroupOfPeople; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.ContentValues; import android.content.DialogInterface; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Toast; public class SendSelected extends Activity{ private Button yes_selected,no_selected; private MyAdapter adapter; private ListView list; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.sendselected); yes_selected=(Button)findViewById(R.id.yes_selected); no_selected=(Button)findViewById(R.id.no_selected); list=(ListView)findViewById(R.id.listSelected); adapter=new MyAdapter(SendSelected.this); list.setAdapter(adapter); list.setItemsCanFocus(false); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); list.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { // TODO Auto-generated method stub ViewHolder vHollder = (ViewHolder) view.getTag(); //在每次获取点击的item时将对于的checkbox状态改变,同时修改map的值。 vHollder.cBox.toggle(); MyAdapter.isSelected.put(position, vHollder.cBox.isChecked()); } }); yes_selected.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub AlertDialog.Builder builder = new Builder(SendSelected.this); builder.setMessage("确认发送飞信吗?"); builder.setTitle("提示"); builder.setPositiveButton("确认",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub List<Map<String, Object>> listaddapter=adapter.getData(); final ArrayList<String> listItem1=new ArrayList<String>(); final ArrayList<String> listItem2=new ArrayList<String>(); for(int i=0;i<list.getCount();i++){ if(MyAdapter.isSelected.get(i)){ // ViewHolder vHollder = (ViewHolder) list.getChildAt(i).getTag(); // System.out.println(vHollder.name.getText()); // System.out.println(vHollder.number.getText()); Map<String,Object> map=listaddapter.get(i); // System.out.println(map.get("name_phone")); // System.out.println(map.get("number_phone")); // //发送飞信 // HashMap<String, String> map1=new HashMap<String,String>(); // map1.put("person_name",(String) map.get("name_phone")); // map1.put("person_number",(String) map.get("number_phone")); listItem1.add((String) map.get("name_phone")); listItem2.add((String) map.get("number_phone")); // } } AlertDialog.Builder builder = new Builder(SendSelected.this); builder.setMessage("是否需要为发送的人建立群组?"); builder.setTitle("提示"); builder.setPositiveButton("确认",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub LayoutInflater factory = LayoutInflater.from(SendSelected.this); final View textEntryView = factory.inflate(R.layout.myview,null); final EditText edit_text = (EditText) textEntryView.findViewById(R.id.group_name); AlertDialog.Builder builder = new AlertDialog.Builder(SendSelected.this); builder.setTitle("请输入群组名称:"); builder.setView(textEntryView); builder.setPositiveButton("确认", new DialogInterface .OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub if(edit_text.getText().length()!=0){ //存储进数据库 ContentValues values=new ContentValues(); String groupname=edit_text.getText().toString(); values.put("group_name", groupname); GroupOfPeople dbHelper=new GroupOfPeople(SendSelected.this, "Group"); SQLiteDatabase db=dbHelper.getWritableDatabase(); db.insert("groupName",null,values); //存储数据 List<Map<String, Object>> listaddapter=adapter.getData(); for(int i=0;i<list.getCount();i++){ if(MyAdapter.isSelected.get(i)){ Map<String,Object> map=listaddapter.get(i); ContentValues valueGroup=new ContentValues(); valueGroup.put("groupname", groupname); valueGroup.put("person_name", map.get("name_phone").toString()); valueGroup.put("person_number",map.get("number_phone").toString()); db.insert("groupPerson",null,valueGroup); } } db.close(); dbHelper.close(); } else{ Toast.makeText(SendSelected.this, "输入错误,请重新输入", Toast.LENGTH_LONG); } } }); builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub dialog.dismiss(); } }); builder.create().show(); } }); builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub dialog.dismiss(); } }); builder.create().show(); dialog.dismiss(); Intent i=new Intent(); i.putStringArrayListExtra("name",listItem1); i.putStringArrayListExtra("number",listItem2); i.setClass(SendSelected.this, SendMessageSelected.class); startActivity(i); } }); builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub dialog.dismiss(); } }); builder.create().show(); } }); no_selected.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub AlertDialog.Builder builder = new Builder(SendSelected.this); builder.setMessage("确认退出飞信群发吗?"); builder.setTitle("提示"); builder.setPositiveButton("确认",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub dialog.dismiss(); SendSelected.this.finish(); } }); builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub dialog.dismiss(); } }); builder.create().show(); } }); } }