简体   繁体   中英

Send and Receive message not display in listview

I develop sms app using smsManager. I send and receive sms successfully but send and receive message not display in listview. I use listview adapter for display message in listview but nothing. Listview custom adapter code below:

 public class MyCustomAdapter extends ArrayAdapter<String> {

        public MyCustomAdapter(Context context, int textViewResourceId,
                final String wordslist) {
            super(context, textViewResourceId);

        }

        TextView txt_worditem;

        @SuppressLint("ViewHolder") @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            try {
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.worditem, parent, false);
                txt_worditem = (TextView) row
                        .findViewById(R.id.main_txt_worditem);
                //txt_worditem.setText(wordslist.get(position));
                                // txt_worditem.setBackgroundColor(55 + AppSettings.bck_color);
            } catch (Exception e) {
                Toast.makeText(Main.this, e.toString(), Toast.LENGTH_LONG)
                .show();
            }

            return row;
        }
    }

I set MyCustomAdapter in onCreate() method:

   MyCustomAdapter mdp = new MyCustomAdapter(getApplicationContext(),R.layout.worditem, wordslist);
   lv.setAdapter(mdp);
   lv.setVisibility(View.VISIBLE);

Everything fine in code no error occurred but send and receive message not display in listview. Please help me for displaying message in listview.

In your MyCustomAdapter constructor

public MyCustomAdapter(Context context, int textViewResourceId,
                final String wordslist) {
    super(context, textViewResourceId);

}

final String wordslist should be List<String> wordsList .

your super call should be

super(context, textViewResourceId, wordsList);

So overall it will look like this

public MyCustomAdapter(Context context, int textViewResourceId,
                List<String> wordsList) {
    super(context, textViewResourceId, wordsList);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM