我对 Java 很陌生,遇到了一个问题。我已经设置了一个 TextView 并希望在setText
从我的对话框中单击一个按钮时调用该方法。这TextView
是在我的主要活动中设置的。我没有将它初始化为静态,因为这会产生错误。有问题的代码行是 -Tabs.total.setText("PRINTING TO TEXT VIEW");
我希望它设置我TextView
在我的类选项卡中定义的内容。
变量total
是这样定义的 -
TextView total = (TextView) findViewById(R.id.total_view);
我已经寻找了很多关于这个问题的材料,但到目前为止还没有找到解决方案。我希望有人能帮忙。谢谢!!
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final View v;
if(convertView==null){
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.scrollergrid, null);
final TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setTag(pos);
tv.setText(mItems[pos]);
TextView price = (TextView)v.findViewById(R.id.price_text);
price.setText("$" + Prices[pos]);
pos += 1;
final ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.getLayoutParams().height = 150;
iv.getLayoutParams().width = 150;
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
iv.setImageResource(mThumbIds[position]);
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
id = tv.getTag();
System.out.println(mItems[(Integer) id] + " $" + Prices[(Integer) id]);
final Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.alertdialog);
dialog.setTitle(mItems[(Integer) id]);
ImageView dialogImage = (ImageView) dialog.findViewById(R.id.alert_image);
dialogImage.setImageResource(mThumbIds[(Integer) id]);
TextView itemDescription = (TextView) dialog.findViewById(R.id.item_description);
itemDescription.setText("A nice little piece of food. Good for all the family. Full of flavour!!");
TextView itemPrice = (TextView) dialog.findViewById(R.id.item_price);
itemPrice.setText("$" + Prices[(Integer) id]);
Button goBack = (Button) dialog.findViewById(R.id.go_back);
goBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
Button order = (Button) dialog.findViewById(R.id.order);
order.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Tabs.Order.add(mItems[(Integer) id] + " " + Prices[(Integer) id]);
System.out.println(Tabs.Order);
Tabs.total.setText("HIIII");
dialog.cancel();
}
});
dialog.show();
}
});
}
else
{
v = convertView;
}
return v;
}
}