乱七八糟

1.  Activity中设置了一个popuWindow,popuWindow有数据要返回给activity,用接口回调实现,具体如下

在popuWindow中定义一个接口:

private Callback callback;
private Vector<Boolean> skills;

public SkillsPopuWindow(Context context){
    this.context = context;
    callback = (Callback)context;
}

skills = new Vector<Boolean>();
//此处 实例化skills的代码省略,总之,这儿是获取skills或者给skills赋值

callback.getSkills(skills);

public interface Callback {
        public void getSkills(Vector<Boolean> skills);
    }

      在Activity中 实现这个接口:

      

public class XXXActivity extends Activity implements SkillsPopuWindow.Callback{
    private Vector<Boolean> skills;

    public void getSkills(Vector<Boolean> skills) {
        this.skills = skills;
        Log.e("skills.size=",skills.size() + "");
    }

}

2.  设置edittext 只能输入数字(点击edittext,弹出数字键盘)

android:numeric="integer"

3. 设置edittext为密码框

android:inputType="textPassword"

4.  android studio中,把快捷键设置成和e>clipse一样:

    crtl + alt + s 打开settings(或者 files -> settings):搜索栏中输入keymap,在keymaps的下拉框中选择 eclipse,application,ok。


5. eclipse 所有xml文件打不开:


6. eclipse 所有的xml文件都打不开:

    window -> perference -> xml -> xml files -> editor :      把勾去掉。重启clipse。(记得一定要重启)

7. 在xm文件(string.xml)中设置数组,在代码(activity)中访问:

<string-array name="hetian_city_item">
        <item>和田</item>
        <item>和田县</item>
        <item>墨玉县</item>
</string-array>


在activity中访问:
getResources().getStringArray(R.array.abei_city_item);

不在activity中访问:

context.getResources().getStringArray(R.array.abei_city_item)

8. EditText设置不可点击: 

android:focusableInTouchMode="false"

9. 在子线程中更新了2个list,怎样同时传递给handler:

private ArrayList<String> countyList;
private ArrayList<Integer> countyDistrictIDList;

 countyDistrictIDList = new ArrayList<Integer>();
 countyList = new ArrayList<String>();

在子线程中携带数据:
Message msg = handler.obtainMessage();
msg.what = 1;
bundle = new Bundle();
bundle.putStringArrayList("countyList", countyList);
bundle.putIntegerArrayList("countyDistrictIDList", countyDistrictIDList);
msg.setData(bundle);
msg.sendToTarget();
在handler中接收数据:
Bundle bundle = msg.getData();
countyList = bundle.getStringArrayList("countyList");
countyDistrictIDList = bundle.getIntegerArrayList("countyDistrictIDList");

10. 捕捉返回键动作:
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            setRememberChoose();//这儿做相应操作
            return super.onKeyDown(keyCode, event);
        }
        return false;
    }
11. popuWindow按返回键,点击白空处 不消失的原因:
   没有设置背景(在xml文件中设置不管用),加上这句就ok了:
 //如果你想设置背景,可以在xml文件中设置,也可以在这儿设置,如果没有背景,可以设置个空的,如上。 
 this.setBackgroundDrawable(new BitmapDrawable());
12. 从assets文件夹中读取(解析).json格式的文件:
   需要注意的地方:
   1. 在android studio中,默认创建的安卓工程没有assets文件夹,你自己创建时要放对位置,放错的话读取不到的。在src的main里面。
   2. .json文件必须是非格式化的。像这样:
   
说到这儿,给大家推荐一个很不错的json工具,jsonview。下载链接:点击打开链接
<pre name="code" class="java" style="font-size: 15.454545021057129px;">proviceDistrictIDList <span style="font-family: 'Source Code Pro'; font-size: 11.3pt;">= new ArrayList<Integer>();</span>
proviceList = new ArrayList<String>();
JSONObject json = getJson(district_json, context);//<span style="font-family: 'Source Code Pro';">district_json是我自己的json文件的文件名</span>
getProvice(json);//获取到数据,并存到<span style="font-family: 'Source Code Pro';">proviceDistrictIDList和</span><span style="font-family: 'Source Code Pro';">proviceList中。</span>

//读取assets文件夹下的文件,并以字符串的形式返回。
	// fileName:要读取的文件名
	public String getJson(String fileName,Context context) {

		StringBuilder stringBuilder = new StringBuilder();
		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(
					context.getAssets().open(fileName)));
			String line;
			while ((line = bf.readLine()) != null) {
				stringBuilder.append(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return stringBuilder.toString();
	}
 
private void getProvice(String json) {

        proviceDistrictIDList = new ArrayList<Integer>();
        proviceList = new ArrayList<String>();

        try {
            JSONArray array = new JSONArray(json);
            if (array.length() > 0) {
                for (int i = 0; i < array.length(); i++) {
                    JSONObject proviceJson = (JSONObject) array.get(i);
                    proviceList.add(proviceJson.getString("name"));
                    proviceDistrictIDList.add(proviceJson.getInt("id"));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


 
 
 
 


      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值