当前位置:  编程技术>移动开发
本页文章导读:
    ▪扩张GridView显示文字以及BaseAdapter的集成        扩展GridView显示文字以及BaseAdapter的集成 可以参考http://developer.android.com/guide/tutorials/views/hello-gridview.html 然后只需要修改: public class MyAdapter extends BaseAdapter {      private Context context;      pr.........
    ▪ 电话短信有关问题        电话短信问题 其实无论呼入呼出 都可以使用receive捕获相关信息,当然 android不支持程序不能拨电话的 我们也是间接实现 public void onReceive(Context context, Intent intent){     String action = intent.getAct.........
    ▪ 获取系统相本中图片的方法       获取系统相册中图片的方法 原文地址:获取系统相册中图片的方法http://www.aisidachina.com/forum/viewthread.php?tid=244定义一个按钮连接以下方法:- (IBAction)selectExistingPicture { if ([UIImagePickerControlle.........

[1]扩张GridView显示文字以及BaseAdapter的集成
    来源: 互联网  发布时间: 2014-02-18
扩展GridView显示文字以及BaseAdapter的集成

可以参考http://developer.android.com/guide/tutorials/views/hello-gridview.html
然后只需要修改:
public class MyAdapter extends BaseAdapter {
     private Context context;
     private String[] texts = {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "eee", "hhh", "iii"};
     public MyAdapter(Context context) {   
      this.context = context;
     }
     public int getCount() {    return 9;}
     public Object getItem(int position) {    return null;}
     public long getItemId(int position) {    return 0;}
     public View getView(int position, View convertView, ViewGroup parent) {
         TextView tv;   
         if (convertView == null) {
                 tv = new TextView(context);       
                 tv.setLayoutParams(new GridView.LayoutParams(85, 85));
                     }
           else {
                  tv = (TextView) convertView;  
                   }
             tv.setText(texts[position]);   
             return tv;
       }

view集成的方法
public View getView(int position, View contentView, ViewGroup arg2)
    {        ViewHolder holder;       
           if (contentView == null) {
                       holder = new ViewHolder();           
                       contentView = inflater.inflate(R.layout.my_magic_list,null);          
                        holder.label = (TextView) contentView.findViewById(R.id.label);           
                        contentView.setTag(holder);        }
            else {            holder = (ViewHolder) contentView.getTag();        }       
            holder.label.setText(getLabel());       
            return contentView;    }

•Use convertView
•If you have images, don't scale your images on the fly. Use Bitmap.createScaledBitmap to create a scaled bitmap and put that into your views
•Use a ViewHolder so you don't have to call a bunch of findViewByIds() every time
•Decrease the complexity of the views in your listview. The fewer subviews, the better. RelativeLayout is much better at this than, say, LinearLayout. And make sure to use if you're implementing custom views.

4.LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);   
final View dialogView = li.inflate(R.layout.edit_event, null);   
ArrayList<String> routes = new ArrayList<String>(); 
ArrayAdapter<String> aa = new ArrayAdapter<String>(GOFdroid.this, android.R.layout.simple_spinner_item, routes);
    aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
     Spinner destSpinner = (Spinner) dialogView.findViewById(R.id.edit_event_destination);
        String dest = events.get(pos).getDestination();
           int routesPos = routes.indexOf(dest);
              Log.d(TAG, "Dest: " + dest + ", pos: " + routesPos); 
              
                   destSpinner.setAdapter(aa);
destSpinner.setSelection(routesPos);
最后一句是在spiner没有显示之前显示一个特定信息

 

5.

  Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null); 
    startManagingCursor(c); 
 
    SpinnerAdapter adapter = new SimpleCursorAdapter(this, 
    // Use a template that displays a text view 
            android.R.layout.simple_gallery_item, 
            // Give the cursor to the list adatper 
            c, 
            // Map the NAME column in the people database to... 
            new String[] {People.NAME}, 
            // The "text1" view defined in the XML template 
            new int[] { android.R.id.text1 }); 
5.只想显示一个

display a static list of String objects

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new String[] {People.NAME}); 
add more String objects to the list later

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new ArrayList<String>()); 


    
[2] 电话短信有关问题
    来源: 互联网  发布时间: 2014-02-18
电话短信问题

其实无论呼入呼出 都可以使用receive捕获相关信息,当然 android不支持程序不能拨电话的 我们也是间接实现
public void onReceive(Context context, Intent intent){
    String action = intent.getAction();
        if (Intent.ACTION_NEW_OUTGOING_CALL.equals(action)) {
                String number = getResultData();
                        if (number.startsWith(BYPASS_PREFIX)) {
                                     setResultData(number.substring(BYPASS_PREFIX.length()));
                               }
                         else {             // do additional processing        }    }

2.拆解短信
http://www.androidcompetencycenter.com/2008/12/android-api-sms-handling/
public class SMSReceiver extends BroadcastReceiver{
    public void onReceive(Context context, Intent intent)    {
            Bundle myBundle = intent.getExtras();       
            SmsMessage [] messages = null;
            String strMessage = "";
                    if (myBundle != null)
                            {
                                        Object [] pdus = (Object[]) myBundle.get("pdus");
                                        messages = new SmsMessage[pdus.length];
                                        for (int i = 0; i < messages.length; i++)
                                                   {
                                                                  messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                                                                  strMessage += "SMS From: " + messages[i].getOriginatingAddress();
                                                                  strMessage += " : ";               
                                                                  strMessage += messages[i].getMessageBody();
                                                                                  strMessage += "\n";          
                                                     }
               Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();        }    }}
3.<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.neocodenetworks.smsfwd"
        android:versionCode="1" 
        android:versionName="1.0">   
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
                <receiver android:name=".SmsReciever">
                            <intent-filter>
                                           <action android:name="android.provider.telephony.SMS_RECIEVED"></action>           
                            </intent-filter>
                </receiver>
               
       </application>
      
     <uses-sdk android:minSdkVersion="6" />   
     <uses-permission android:name="android.permission.INTERNET"></uses-permission>  
      <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
      </manifest>

public class SmsReciever extends BroadcastReceiver {
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
       private static final String TAG = "smsfwd";
           @Override
          public void onReceive(Context context, Intent intent) {
                 Log.i(TAG, "Intent recieved: " + intent.getAction());
                   if (intent.getAction().equil(SMS_RECEIVED)) {
                              Bundle bundle = intent.getExtras();
                                         if (bundle != null) {
                                                        Object[] pdus = (Object[])bundle.get("pdus");
                                                       
                                                        final SmsMessage[] messages = new SmsMessage[pdus.length];
                                                        for (int i = 0; i < pdus.length; i++) {
                                                        messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                                                                       }
                                       if (messages.length > -1) {
                                                Log.i(TAG, "Message recieved: " + messages[0].getMessageBody()); 
                                               
                                                 NetComm.SendMessage("me", messages[0].getOriginatingAddress(), messages[0].getMessageBody());
                                                                 }            }        }    }

4.得到所有短信
Uri allMessage = Uri.parse("content://sms/");ContentResolver cr = getContentResolver();Cursor c = cr.query(allMessage, null, null, null, null);while  (c.moveToNext()) {   String row = c.getString(1);}
5.得到未读短信
for (int i = 0; i < messages.length; i++)            {                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);                from = ""+messages[i].getOriginatingAddress();                body = ""+messages[i].getMessageBody();                inSIM = (messages[i].getIndexOnSim() != -1);                if (inSIM)                {                    int status = messages[i].getStatusOnSim();                    if (status == SmsManager.STATUS_ON_SIM_UNREAD)                    {                       Toast.makeText(context, "Message Unread on SIM: "+from+": "+body, Toast.LENGTH_SHORT).show();                    }                }                            } 

 

 

5.得到来电的电话号码:

<receiver android:name=".CustomBroadcastReceiver"> 
        <intent-filter> 
                <action android:name="android.intent.action.PHONE_STATE" />      
        </intent-filter> 
</receiver> 
 
</application> 
<uses-sdk android:minSdkVersion="5" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_CONTACTS" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
public class CustomPhoneStateListener extends PhoneStateListener { 
 
private static final String TAG = "CustomPhoneStateListener"; 
 
public void onCallStateChange(int state, String incomingNumber){ 
 
        Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!"); 
        Log.v(TAG, incomingNumber); 
 
        switch(state){ 
                case TelephonyManager.CALL_STATE_RINGING: 
                        Log.d(TAG, "RINGING"); 
                        break; 
        }        

public class CustomBroadcastReceiver extends BroadcastReceiver { 
 
private static final String TAG = "CustomBroadcastReceiver"; 
 
@Override 
public void onReceive(Context context, Intent intent) { 
        Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!"); 
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
        CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener(); 
 
    telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); 
 
 
    Bundle bundle = intent.getExtras(); 
    String phoneNr= bundle.getString("incoming_number"); 
        Log.v(TAG, "phoneNr: "+phoneNr); 
 

4. 比较好的实例讲解http://mobiforge.com/developing/story/sms-messaging-android


    
[3] 获取系统相本中图片的方法
    来源: 互联网  发布时间: 2014-02-18
获取系统相册中图片的方法
原文地址:获取系统相册中图片的方法
http://www.aisidachina.com/forum/viewthread.php?tid=244

定义一个按钮连接以下方法:
- (IBAction)selectExistingPicture {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) 
        {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsImageEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] 
                              initWithTitle:@"访问图片库错误" 
                              message:@"" 
                              delegate:nil 
                              cancelButtonTitle:@"OK!" 
                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


再调用以下委托:
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
{
        imageView.image = image;        //imageView为自己定义的UIImageView                
    [picker dismissModalViewControllerAnimated:YES];
    
}

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
WEB前端 iis7站长之家
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3