0

my app has listview and each item has Smiles Code for example " Hello World :) its smiley Day :D "

i want to replace :) and :D with exists images in my application but the images has no draw id its in SD folder can i do that ? if so how or where to start !

I've tried to googled it i couldn't found a good solution for my issue

here is my code

@SuppressLint({ "ResourceAsColor", "NewApi" }) public View getView(final int position, View convertView, ViewGroup parent)
{
    final ViewHolder holder;
    final JSONObject p = (JSONObject) getItem(position);

    if(convertView == null)
    {
         convertView = mInflater.inflate(R.layout.postbit, null);
         holder = new ViewHolder();
         convertView.setTag(holder);

         holder.attach_handler       = ( LinearLayout ) convertView.findViewById(R.id.attach_handler);
         holder.attachments_box      = ( LinearLayout ) convertView.findViewById(R.id.attachments_box);
         holder.postbit_useravatar   = ( ImageView ) convertView.findViewById(R.id.postbit_useravatar);
         holder.postbit_username     = ( TextView ) convertView.findViewById(R.id.postbit_username);
         holder.postbit_timestamp    = ( TextView ) convertView.findViewById(R.id.postbit_timestamp);
         holder.postbit_boxmenu      = ( ImageView ) convertView.findViewById(R.id.postbit_boxmenu);
         holder.postbit_threadtitle  = ( TextView ) convertView.findViewById(R.id.postbit_threadtitle);
         holder.postbit_message      = ( TextView ) convertView.findViewById(R.id.postbit_message);
         holder.show_deletedicon     = ( ImageView ) convertView.findViewById(R.id.show_deletedicon);
         holder.show_quotedicon      = ( ImageView ) convertView.findViewById(R.id.show_quotedicon);

         //Set Fonts
         holder.postbit_username.setTypeface(Api.font_short);
         holder.postbit_timestamp.setTypeface(Api.font_text);
         holder.postbit_threadtitle.setTypeface(Api.font_title);
         holder.postbit_message.setTypeface(Api.font_text);
   }
   else
    {
         holder = (ViewHolder) convertView.getTag();
    }

            /*********************************
             * Add Values
             */
            String deletedby   = context.getResources().getString(R.string.post_deleted_byreason);

           try {
                   deletedby   = deletedby.replace("{1}", p.getString("del_username"));
                   deletedby   = deletedby.replace("{2}", p.getString("del_reason"));
               } catch (JSONException e) {
                   deletedby   = context.getResources().getString(R.string.deleted_post);                      
                   e.printStackTrace();
                   }

            String PostMessage = p.getString("pagetext");

            //if deleted
            if( p.getInt("visible") == 2  )
            {
                holder.show_deletedicon.setVisibility(View.VISIBLE);    
            }

            try {
              //IF deleted and aim not Admin
              if ( p.getInt("show_delete") == 0 && p.getInt("visible") == 2 )
              {
                holder.attach_handler.setVisibility(View.GONE);
                PostMessage = deletedby;
              }else
              if( p.getInt("visible") == 2  )   
              {
                PostMessage = PostMessage+" \n\n"+deletedby;
              }
            } catch (JSONException e) {
              e.printStackTrace();
            }

            holder.postbit_username.setText(p.getString("username"));
            holder.postbit_threadtitle.setText(ShowThread.threadTitle);
            holder.postbit_message.setAutoLinkMask(Linkify.ALL);

//here the Html Code
            holder.postbit_message.setText(Html.fromHtml(PostMessage));
Noob
  • 2,857
  • 6
  • 33
  • 47

1 Answers1

1

Have you tried using ImageSpan??

ImageSpan is = new ImageSpan(context, resId);
text.setSpan(is, index, index + strLength, 0);

You can put images directly in your TextView/EditText.

Aman Gautam
  • 3,549
  • 2
  • 21
  • 25
  • sounds good and yes this is what aim looking for , but aim still newer in android is there any example for this class ! how to use it ? – Noob Aug 27 '13 at 17:04
  • checkout this link http://stackoverflow.com/a/3177667/1234007 . You need to first find the positions of your smileys and replace them with images using ImageSpan – Aman Gautam Aug 27 '13 at 17:10
  • if i have more than 200 emotions in listview i guess its will crash the application for memory leak if i use indexOf right ? – Noob Aug 27 '13 at 17:22
  • If that is also concern, I recommend using a StringBuffer instead. That will be good enough for you as it mutable. – Aman Gautam Aug 27 '13 at 17:48