发送和接收消息不显示在列表视图中

时间:2015-08-05 05:14:47

标签: android listview android-listview

我使用smsManager开发短信应用程序。我成功发送和接收短信但发送和接收不在列表视图中显示的消息。我使用listview适配器在listview中显示消息,但没有。 Listview自定义适配器代码如下:

 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;
        }
    }

我在MyCustomAdapter方法中设置onCreate()

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

代码中的所有内容都没有发生错误,但发送和接收消息未显示在listview中。请帮我在listview中显示消息。

1 个答案:

答案 0 :(得分:0)

在MyCustomAdapter构造函数中

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

}

final String wordslist应为List<String> wordsList

你的超级电话应该是

super(context, textViewResourceId, wordsList);

总的来说,它看起来像这样

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

}