我很抱歉我的英语不好,但这是我的问题:
我使用像 ArrayAdapter 这样的自定义 ListView 并在我的主 Activity 中创建我的 ArrayAdapter 作为实习生类:
/*This is my Main Activity*/
public class KhassaideActivity extends Activity {
ViewHolder holder;
KhassaideAdapterbi listadapter ;
ListView l ;
@Override
protected void onCreate(Bundle savedInstanceState) {
l= (ListView) findViewById(R.id.listDieuzbou);
listadapter = new KhassaideAdapterbi(this, R.layout.affichage_khassaide, rowItems);
l.setAdapter(listadapter);
}
/*This is my intern class ArrayAdapter*/
private class KhassaideAdapterbi extends ArrayAdapter<RowItem>{
Context context;
public KhassaideAdapterbi(Context context, int resourceId,
List<RowItem> items) {
super(context, resourceId, items);
this.context = context;
}
public class ViewHolder {
ImageView imageView;
TextView trad;
TextView trans;
TextView number;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
RowItem rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.affichage_khassaide, null);
holder.number = (TextView) convertView.findViewById(R.id.number);
holder.trad = (TextView) convertView.findViewById(R.id.traduction);
holder.trans = (TextView) convertView.findViewById(R.id.transcription);
holder.imageView = (ImageView) convertView.findViewById(R.id.arabe);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.trad.setText(rowItem.getTitle());
holder.trans.setText(rowItem.getDesc());
holder.imageView.setImageResource(rowItem.getImageId());
holder.number.setText(rowItem.getNumber());
return convertView;
}
}
因此,在我的主要活动中,当用户单击这样的菜单项时,我想访问和共享两个 TextView 的值:
case R.id.action_share:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, listadapter.holder.trad.getText());
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
但我在这一行listadapter.holder.trad.getText()得到一个 NullPointerException
有人有解决方案吗?先感谢您。再次为这种糟糕的英语感到抱歉