【发布时间】:2013-10-25 05:18:07
【问题描述】:
我在选择多个联系人的代码中使用 CustomMultiAutoCompleteTextView 参考 this 选择多个联系人,但我想显示在 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
我能知道为什么会出现这个错误吗?如何在主要活动中获取选定的联系信息任何机构帮助我解决这个问题
【问题讨论】:
-
你应该包含你的错误日志。
-
我包括在内。在按钮单击中访问 map.size() 时出现错误
标签: android