settypeface在baseadapter中使用时崩溃了android

时间:2015-07-24 17:28:52

标签: android listview baseadapter

我正在使用此代码

public View getView(final int position, View convertView, ViewGroup parent) {
            // Declare Variables
            TextView rank;
            TextView country;
          //  TextView population;
            ImageView flag;
            inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View itemView = inflater.inflate(R.layout.listview_item, parent, false);
            // Get the position
            resultp = data.get(position);
            // Locate the TextViews in listview_item.xml
            rank = (TextView) itemView.findViewById(R.id.rank);
           country = (TextView) itemView.findViewById(R.id.country);
            country.setText("sfsdfs");
           // population = (TextView) itemView.findViewById(R.id.population);
            // Locate the ImageView in listview_item.xml
            flag = (ImageView) itemView.findViewById(R.id.flag);
            // Capture position and set results to the TextViews
            rank.setText(resultp.get(MainActivity.RANK));
            //country.setText("????????");
            Typeface myTypeface = Typeface.createFromAsset(context.getAssets(),"fonts/JameelNooriNastaleeqKasheeda.ttf");
            TextView population  = (TextView) itemView.findViewById(R.id.population);
            population.setTypeface(myTypeface);
            population.setText(resultp.get(MainActivity.POPULATION));
            // Capture position and set results to the ImageView
            // Passes flag images URL into ImageLoader.class
            imageLoader.DisplayImage(resultp.get(MainActivity.FLAG), flag);
            // Capture ListView item click
            itemView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    // Get the position
                    resultp = data.get(position);
                    Intent intent = new Intent(context, SingleItemView.class);
                    // Pass all data rank
                    intent.putExtra("rank", resultp.get(MainActivity.RANK));
                    // Pass all data country
                    intent.putExtra("country", resultp.get(MainActivity.COUNTRY));
                    // Pass all data population
                    intent.putExtra("population",
                            resultp.get(MainActivity.POPULATION));
                    // Pass all data flag
                    intent.putExtra("flag", resultp.get(MainActivity.FLAG));
                    // Start SingleItemView Class
                    context.startActivity(intent);
                }
            });
            return itemView;
        }

0 个答案:

没有答案