当前位置:  编程技术>移动开发
本页文章导读:
    ▪Sinatra:Request#process_route(pattern, keys, conditions)        Sinatra::Request#process_route(pattern, keys, conditions)     # If the current request matches pattern and conditions, fill params    # with keys and call the given block.    # Revert params afterwards.    #        # Returns pass.........
    ▪ ExpandableListView小图标轮换        ExpandableListView小图标替换 ExpandableListView的小图标有个状态,一个是不点击的情况,一个是点击后展开的情况,用xml配置如下:<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://s.........
    ▪ 撤除自动获取焦点(默认进来焦点到edittext),取消进入呼出软件盘       取消自动获取焦点(默认进来焦点到edittext),取消进入呼出软件盘 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/checkinlinear" android:layout_below="@id/.........

[1]Sinatra:Request#process_route(pattern, keys, conditions)
    来源: 互联网  发布时间: 2014-02-18
Sinatra::Request#process_route(pattern, keys, conditions)
    # If the current request matches pattern and conditions, fill params
    # with keys and call the given block.
    # Revert params afterwards.
    #   
    # Returns pass block.
    def process_route(pattern, keys, conditions)
      @original_params ||= @params
      route = @request.route
      route = '/' if route.empty? and not settings.empty_path_info?
      if match = pattern.match(route)
        values = match.captures.to_a
        params =
          if keys.any?
            keys.zip(values).inject({}) do |hash,(k,v)|
              if k == 'splat'
                (hash[k] ||= []) << v
              else
                hash[k] = v
              end
              hash
            end
          elsif values.any?
            {'captures' => values}
          else
            {}
          end
        @params = @original_params.merge(params)
        @block_params = values
        catch(:pass) do
          conditions.each { |cond|
            throw :pass if instance_eval(&cond) == false }
          yield
        end
      end
    ensure
      @params = @original_params
    end

    
[2] ExpandableListView小图标轮换
    来源: 互联网  发布时间: 2014-02-18
ExpandableListView小图标替换
ExpandableListView的小图标有个状态,一个是不点击的情况,一个是点击后展开的情况,用xml配置如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:state_expanded="true" android:drawable="@drawable/narrow_select" />
       <item android:drawable="@drawable/narrow" />
</selector>

Java的代码如下:
ExpandableListView listView = getExpandableListView();
listView.setGroupIndicator(this.getResources().getDrawable(R.drawable.group_icon_selector));

注意:不知道为什么,使用自定义的GroupIndicator会发生图片被拉伸的现象,为了解决这个问题需要定义一个长度为groups.length的boolean数组:
private boolean[] isOpen=new boolean[groups.length];

然后重写OnGroupCollapseListener和OnGroupExpandListener用于修改当前group的状态:
expandableListView.setOnGroupCollapseListener(onGroupCollapseListener);
expandableListView.setOnGroupExpandListener(onGroupExpandListener);
expandableListView.setGroupIndicator(null);//不要自带的了!!!
OnGroupCollapseListener onGroupCollapseListener=new OnGroupCollapseListener(){

			@Override
			public void onGroupCollapse(int groupPosition) {
				// TODO Auto-generated method stub
				isOpen[groupPosition]=false;
			}
			
		};
		
OnGroupExpandListener onGroupExpandListener=new OnGroupExpandListener(){

			@Override
			public void onGroupExpand(int groupPosition) {
				// TODO Auto-generated method stub
				isOpen[groupPosition]=true;
			}
			
		};

最后在getGroupView()中应用,代码片段如下:
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
					View convertView, ViewGroup parent) {
				// TODO Auto-generated method stub
				TextView textView=null;
				if(convertView==null){
					textView=new TextView(mContext);
					AbsListView.LayoutParams lp = new AbsListView.LayoutParams(  
		                    ViewGroup.LayoutParams.FILL_PARENT, 50);  
		            textView.setLayoutParams(lp);
		            textView.setGravity(Gravity.CENTER);
		            textView.setPadding(10, 0, 0, 0);
		            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16.0f);
		            textView.setTextColor(0xFFC6B39C);
		            textView.setBackgroundResource(R.drawable.bg_tv);//bg_tv_expand
		            convertView=textView;
				}else{
					textView=(TextView)convertView;
				}
				//为了处理图标被拉伸的问题!这里采用偷懒的办法让textView傍边产生一个图标,如果GroupView只是一个TextView的话,推荐这样做!
				if(isOpen[groupPosition]){
					Drawable leftDrawable= resources.getDrawable(R.drawable.arrow_down_on);
	            	leftDrawable.setBounds(0, 0, leftDrawable.getMinimumWidth(), leftDrawable.getMinimumHeight());
	            	textView.setCompoundDrawables(leftDrawable, null, null, null);
				}else{
					Drawable leftDrawable= resources.getDrawable(R.drawable.arrow_right_off);
					leftDrawable.setBounds(0, 0, leftDrawable.getMinimumWidth(), leftDrawable.getMinimumHeight());
					textView.setCompoundDrawables(leftDrawable, null, null, null);
				}
				textView.setText(((Market)getGroup(groupPosition)).market);
	            return textView;
}


over!

Android版手风琴(ExpandableListView)

创新源于模仿之四:增强的ExpandableListView

android api里的例子:

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;

import com.example.android.apis.R;

/**
 * Demonstrates expandable lists using a custom {@link ExpandableListAdapter}
 * from {@link BaseExpandableListAdapter}.
 */
public class ExpandableList1 extends ExpandableListActivity {

    ExpandableListAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set up our adapter
        mAdapter = new MyExpandableListAdapter();
        setListAdapter(mAdapter);
        registerForContextMenu(getExpandableListView());
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.setHeaderTitle("Sample menu");
        menu.add(0, 0, 0, R.string.expandable_list_sample_action);
    }
    
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

        String title = ((TextView) info.targetView).getText().toString();
        
        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 
            Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
                    Toast.LENGTH_SHORT).show();
            return true;
        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
            Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
            return true;
        }
        
        return false;
    }

    /**
     * A simple adapter which maintains an ArrayList of photo resource Ids. 
     * Each photo is displayed as an image. This adapter supports clearing the
     * list of photos and adding a new photo.
     *
     */
    public class MyExpandableListAdapter extends BaseExpandableListAdapter {
        // Sample data set.  children[i] contains the children (String[]) for groups[i].
        private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
        private String[][] children = {
                { "Arnold", "Barry", "Chuck", "David" },
                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                { "Fluffy", "Snuggles" },
                { "Goldy", "Bubbles" }
        };
        
        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return children[groupPosition].length;
        }

        public TextView getGenericView() {
            // Layout parameters for the ExpandableListView
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 64);

            TextView textView = new TextView(ExpandableList1.this);
            textView.setLayoutParams(lp);
            // Center the text vertically
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            // Set the text starting position
            textView.setPadding(36, 0, 0, 0);
            return textView;
        }
        
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getChild(groupPosition, childPosition).toString());
            return textView;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getGroup(groupPosition).toString());
            return textView;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }
}



    
[3] 撤除自动获取焦点(默认进来焦点到edittext),取消进入呼出软件盘
    来源: 互联网  发布时间: 2014-02-18
取消自动获取焦点(默认进来焦点到edittext),取消进入呼出软件盘
  <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
                  android:id="@+id/checkinlinear" android:layout_below="@id/assetnameet"
                  android:focusable="true"  android:focusableInTouchMode="true"
                  android:lineSpacingExtra="5dip">
        
        <EditText android:id="@+id/checkin_content" android:layout_height="50dip" android:layout_width="200dip"
                  android:layout_weight="1" android:hint="@string/checkin_content_hint" android:singleLine="true"/>
      
        <Button android:text="@string/checkin_submit_btn" android:id="@+id/checkin_submitbtn"
                android:layout_height="wrap_content" android:layout_width="wrap_content"
                android:layout_weight="3"/>
    </LinearLayout>

 android:focusable="true"  android:focusableInTouchMode="true"

 

此前,当我进入做项目的时候!发现,当我进入到对应的ui中,焦点会自动的到edittext中,这样就会呼出软键盘!我在网上找了一些资料!有的是关闭,或者监控软键盘状态,或者焦点位置!

   但是!这些都不是我项目想要的!

  我想要的仅仅是第一次进入到对应ui的时候,不要呼出软键盘,当用户点击的时候,才呼出软键盘!

 

 

 而在linearyout中加入这两行代码就能实现我的要求了了!


    
最新技术文章:
▪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添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪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