应用程序无法在Android 4.0及更高版本中运行

应用程序无法在Android 4.0及更高版本中运行,第1张

概述我试图在编辑文本中显示图像和文本,但它不适用于冰淇淋三明治和Jellybean ..  它在以下版本运行良好. 当活动暂停并再次恢复时,它会在编辑文本中显示图像名称而不是图像以及文本. 请参考图像和相关代码 public class MainActivity extends Activity implements OnClickListener, OnItemClickListe 我试图在编辑文本中显示图像和文本,但它不适用于冰淇淋三明治和Jellybean ..
 它在以下版本中运行良好.

当活动暂停并再次恢复时,它会在编辑文本中显示图像名称而不是图像以及文本.

请参考图像和相关代码

public class MainActivity extends Activity implements OnClickListener,OnItemClickListener {     String path = Environment.getExternalStorageDirectory().getabsolutePath()            + "/Emoticons";HashMap<String,Integer> emoticons = new linkedHashMap<String,Integer>();ArrayList<String> arrayList = new ArrayList<String>();Bitmap bitmap;EditText editText;Imagebutton cat_one;ArrayList<String> name = new ArrayList<String>();VIEw vIEw;CharSequence[] namesList = { "Email"};Dialog dialog;GrIDVIEw grIDVIEw;@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.main);    if (Environment.getExternalStorageState().equals(            Environment.MEDIA_MOUNTED)) {        file sd = new file(path);        if (!sd.exists())            sd.mkdirs();    }    addComponents();    addListeners();}private voID fillArrayList() {    Iterator<Entry<String,Integer>> iterator = emoticons.entrySet()            .iterator();    Log.d("Iterator",iterator.toString());    while (iterator.hasNext()) {        Entry<String,Integer> entry = iterator.next();        Log.d("Entry",entry.getKey());        arrayList.add(entry.getKey());    }}private voID getcategory(String cat_name) {    // Todo auto-generated method stub    if (name.size() > 0)        name.clear();    if (emoticons.size() > 0)        emoticons.clear();    if (arrayList.size() > 0)        arrayList.clear();    FIEld names[] = R.drawable.class.getFIElds();    for (FIEld f : names) {        if (f.getname().contains(cat_name)) {            name.add(f.getname());        }    }    for (int i = 0; i < name.size(); i++) {        int ID = getResources().getIDentifIEr(name.get(i),"drawable",getPackagename());        Log.d("Drawable Folder",name.get(i).toString());        emoticons.put(name.get(i),ID);    }    fillArrayList();}private voID addListeners() {    // Todo auto-generated method stub    cat_one.setonClickListener(this);    grIDVIEw.setonItemClickListener(this);}private voID addComponents() {    // Todo auto-generated method stub    editText = (EditText) findVIEwByID(R.ID.editText1);    editText.requestFocus();    vIEw = getLayoutInflater().inflate(R.layout.popup,null);    grIDVIEw = (GrIDVIEw) vIEw.findVIEwByID(R.ID.grIDLayout);    dialog = new Dialog(this,R.style.DialogSlIDeAnim);    dialog.requestwindowFeature(Window.FEATURE_NO_Title);    dialog.getwindow().setGravity(Gravity.BottOM);    Window window = dialog.getwindow();    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_touch_MODAL,WindowManager.LayoutParams.FLAG_NOT_touch_MODAL);    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);    dialog.setContentVIEw(vIEw);    dialog.setCanceledOntouchOutsIDe(true);    cat_one = (Imagebutton) findVIEwByID(R.ID.category_one);}public Spannable getSmiledText(Context context,String text) {    SpannableStringBuilder builder = new SpannableStringBuilder(text);    int index;    for (index = 0; index < builder.length(); index++) {        for (Entry<String,Integer> entry : emoticons.entrySet()) {            int length = entry.getKey().length();            if (index + length > builder.length())                continue;            if (builder.subSequence(index,index + length).toString()                    .equals(entry.getKey())) {                builder.setSpan(new ImageSpan(context,entry.getValue()),index,index + length,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);                index += length - 1;                break;            }        }    }    return builder;}class ImageAdapter extends BaseAdapter {    public int getCount() {        return arrayList.size();    }    public Object getItem(int position) {        return arrayList.get(position);    }    public long getItemID(int position) {        return position;    }    public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {        convertVIEw = LayoutInflater.from(MainActivity.this).inflate(                R.layout.row,null);        ImageVIEw imageVIEw = (ImageVIEw) convertVIEw                .findVIEwByID(R.ID.imageVIEw1);        imageVIEw.setBackgroundDrawable(getResources().getDrawable(                emoticons.get(arrayList.get(position))));        Log.d(getLocalClassname(),String.valueOf(emoticons.get(arrayList.get(position))));        return convertVIEw;    }}@OverrIDepublic voID onClick(VIEw v) {    // Todo auto-generated method stub    if (v == cat_one) {        getcategory("good");        grIDVIEw.setAdapter(new ImageAdapter());    }}@OverrIDepublic voID onItemClick(AdapterVIEw<?> arg0,VIEw arg1,int position,long arg3) {    // Todo auto-generated method stub    String value = grIDVIEw.getAdapter().getItem(position).toString();    Spannable spannable = getSmiledText(MainActivity.this,value);    SpannableStringBuilder ssb = new SpannableStringBuilder(            editText.getText()).append(spannable).append(" ");    editText.setText(ssb);    editText.setSelection(editText.getText().length());    editText.setCursorVisible(true);}  }
解决方法 我想我们需要一些追踪才能更好地了解出了什么问题.但是当你无法加载图像时,我想知道是否可能失去了对外部存储目录的访问权限 总结

以上是内存溢出为你收集整理的应用程序无法在Android 4.0及更高版本中运行全部内容,希望文章能够帮你解决应用程序无法在Android 4.0及更高版本中运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1129155.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存