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