我在选择多个联系人的代码中使用 CustomMultiAutoCompleteTextViewthis
选择多个联系人,但我想显示在 toast 消息上选择的数字是什么。当单击按钮时,我修改了该代码main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.krishna.widget.CustomMultiAutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:textColor="@android:color/black"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
我添加了这个字段CustomMultiAutoCompleteTextView.java
public HashMap<String, String> con=new HashMap<String, String>();
用于在此保存联系电话Hashmap
我在
CustomMultiAutoCompleteTextView.java
public void init(Context context){
....
this.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
...
con.put(contact.num.toString(), contact.contactName.toString());
}
});
}
and i modified
MainActivity.java
像这样
public class MainActivity extends Activity implements OnClickListener{
Button b1;
private CustomMultiAutoCompleteTextView phoneNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
phoneNum = (CustomMultiAutoCompleteTextView)
findViewById(R.id.editText);
ContactPickerAdapter contactPickerAdapter = new ContactPickerAdapter(this,
android.R.layout.simple_list_item_1, SmsUtil.getContacts(
this, false));
phoneNum.setAdapter(contactPickerAdapter);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener((OnClickListener) this);
//phoneNum.addTextChangedListener((TextWatcher));
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CustomMultiAutoCompleteTextView phoneNum=(CustomMultiAutoCompleteTextView)findViewById(R.id.editText);
HashMap<String, String> map=(HashMap<String, String>)phoneNum.con;
try{
Toast.makeText(this, map.size(), Toast.LENGTH_LONG).show();
}catch(Exception e)
{
Log.e("eee",e.toString());
}
}
}
现在执行我选择了一个联系人,如果我按下按钮我就在unable to get map size()
那里android.content.res.resources$notfoundexception string resource id #0x1
我能知道为什么会出现这个错误。如何在主要活动中获取选定的联系信息任何机构帮助我解决这个问题