添加飞信好友界面源码,AddPerson.java
package com.huangcheng.FetionAdd; import java.util.List; import java.util.Map; import Android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.ListView; import com.huangcheng.FetionSendThread.AddThread; import com.huangcheng.mainFrame.MyAdapter; import com.huangcheng.mainFrame.MyAdapter.ViewHolder; import com.huangcheng.mainFrame.R; public class AddPerson extends Activity{ private ListView list; private Button yes_add,no_add; private MyAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.addperson); yes_add=(Button)findViewById(R.id.yes_add); no_add=(Button)findViewById(R.id.no_add); list=(ListView)findViewById(R.id.lv); adapter=new MyAdapter(AddPerson.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_add.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub AlertDialog.Builder builder = new Builder(AddPerson.this); builder.setMessage("确认添加飞信吗?"); builder.setTitle("提示"); builder.setPositiveButton("确认",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { // TODO Auto-generated method stub SharedPreferences sharedPreferences=getSharedPreferences("Fetion_Send",Context.MODE_PRIVATE); String pwd=sharedPreferences.getString("password",""); String user=sharedPreferences.getString("username",""); List<Map<String, Object>> listaddapter=adapter.getData(); 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); String to=map.get("number_phone").toString(); AddThread thread=new AddThread(user, pwd, to); thread.start(); } } dialog.dismiss(); AddPerson.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(); } }); no_add.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub AlertDialog.Builder builder = new Builder(AddPerson.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(); AddPerson.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(); } }); } }
程序通过飞信API实现飞信好友的添加。