我们举个例子,假如我们已经获得了手机中保存的联系人姓名和电话号码,并把它们显示在了一个Android ListView中,现在要实现的功能是当点击选中项时直接拨号,那么如何取得此时Android ListView中的号码?
要显示联系人姓名和电话号码,那你现在肯定已经在listview 的item里面放了两个控件吧,假如是textview吧,那你就首先要给listview添加一个OnItemClickListener来监听你点击了那个item,在这个OnItemClickListener里面有个onItemClick方法,这个方法里面有个view参数,那你就可以通过view.findViewById("你的控件名字")来找到了。代码例子:
- ListView listView =(ListView) findViewById(R.id.ListView);
- OnItemClickListener lvItemClickListener=new OnItemClickListener(){
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- final TextView content=(TextView) view.findViewById(R.id.phoneNumber);)
- }
- }
Android中如何使EditText在初始化时不得到焦点
如何使Android EditText在初始化时不得到焦点:
使用:
myEditText.clearFocus();
myEditText.setSelected(false);
都没好用,正确的方法是在EditText上面加一个隐藏的linearLayout,如下:
- <LinearLayout
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:layout_width="0px"
- android:layout_height="0px"
- />
- <EditText
- android:id="@+id/editor"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:paddingRight="55dip"
- android:background="@drawable/register"
- android:editable="false"
- android:maxLines="1"
- android:scrollHorizontally="true"
- android:cursorVisible="false"
- />
Android中用Intent提取缩略图和原始图像提取图像的Thumbnail:
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
- intent.setType("image/*");
- intent.putExtra("return-data", true);
- startActivityForResult(intent, REQUEST_CODE_PHOTO_PICKED);
-
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode != RESULT_OK) {
- return;
- }
- Bitmap bitmap = null;
- ContentResolver resolver = getContentResolver();
- if (requestCode == REQUEST_CODE_PHOTO_PICKED) {
- final Bundle extras = data.getExtras();
- if (extras != null)
- bitmap = extras.getParcelable("data");
- }
- }
- //此方法返回的data 必须小于100k
获取原图:
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
- intent.setType("image/*");
- startActivityForResult(intent, REQUEST_CODE_PHOTO_PICKED);
-
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode != RESULT_OK) {
- return;
- }
- Bitmap bitmap = null;
- ContentResolver resolver = getContentResolver();
- if (requestCode == REQUEST_CODE_PHOTO_PICKED) {
- try {
- Uri originalUri = data.getData();
- Uri thumb = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
- originalUri.getLastPathSegment());
- bitmap = MediaStore.Images.Media.getBitmap(resolver, thumb);
- } catch (IOException e) {
- }
- }
- }