Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:12:06+00:00 2026-06-09T13:12:06+00:00

So I’ve been searching a long time for this, trying out a lot of

  • 0

So I’ve been searching a long time for this, trying out a lot of stuff, but it doesn’t seem to work… I’ve recently started programming for Android, and I’m making a chat-application for a website.

Now I’ve come to a point where I want to add smileys/emoticons to the application, and by searching I found these websites:
http://blog.stylingandroid.com/archives/177
http://www.coderanch.com/t/488673/Android/Mobile/styling-items-ListView

My code:

private void updateList()
{
    ListView list = this.getListView();

    if(!parsedData.isEmpty())
    {
        ArrayAdapter<String> adapter = new MyAdapter(this, R.layout.list_item, parsedData);

    list.setAdapter(adapter);
    list.setTextFilterEnabled(true);
    }
}

class MyAdapter extends ArrayAdapter<String>
{
    ArrayList<String> mStrings;
    LayoutInflater mInflater; 

    public MyAdapter(Context context, int textViewResourceId, ArrayList<String> parsedData)
    {
        super(context, textViewResourceId, parsedData);
        mStrings = parsedData;
        mInflater = (LayoutInflater) HopeloosChatActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            convertView = mInflater.inflate(R.layout.main, null, false);  
        }

        TextView text = (TextView)convertView.findViewById(R.id.TextView);
        SpannableStringBuilder ssb = new SpannableStringBuilder("Test  ");
        Bitmap emoticon = BitmapFactory.decodeResource( getResources(), R.drawable.icon);
        ssb.setSpan(new ImageSpan(emoticon), 5, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 
        text.setText(ssb, BufferType.SPANNABLE);

        return convertView;
    }
}

I do use setContentView(R.layout.main); in the OnCreate()-method

My main.xml contains the ListView part:

<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />

And list_item.xml contains the TextView:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TextView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:autoLink="web"
android:linksClickable="true" >
</Textview>

When I run my code, I get a Nullpointer because text is null, and I’m kinda stuck. Could anyone point me in the right direction or help me a bit?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:12:08+00:00Added an answer on June 9, 2026 at 1:12 pm

    You are inflating convertView using R.layout.main:

    convertView = mInflater.inflate(R.layout.main, null, false);
    

    This isn’t right; you’re inflating your ListView‘s layout each time. Use this instead:

    convertView = mInflater.inflate(R.layout.list_item, null, false);
    

    Additionally, your TextView should be wrapped in a layout, or convertView may be the TextView itself, and findViewById(...) won’t work on it. Actually, thanks to @Jens, this crossed-out text doesn’t apply; using findViewById on the same object you’re looking for will still work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.