我已经在类中初始化对象,如下所示
View popupView; //This is global
我在 onCreate() 方法中创建了 View 对象,如下所示
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
popupView = layoutInflater.inflate(R.layout.activity_filter_form, null);
我想访问 setOnClickListener 中的视图对象,如下所示
popupView.setVisibility(View.VISIBLE);
但上面的行给出了一个错误“popupView 无法解析为一个类型”。请帮忙。
完整代码如下
public class Myclass1 extends Activity
{
TextView tv_addiction_name, tv_today, tv_yesterday, tv_this_week, tv_this_month, tv_total;
ImageView iv_back, iv_filter;
int year, month, day;
int placeData;
Boolean state = false;
DatePickerDialog.OnDateSetListener dateListener;
SQLiteDatabase database;
int cat_id = 0;
View popupView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addiction_details);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
popupView = layoutInflater.inflate(R.layout.activity_filter_addiction_form, null);
popupView.setVisibility(View.INVISIBLE);
Intent intent = getIntent();
final String cat_name = intent.getStringExtra("cat_name");
tv_addiction_name = (TextView) findViewById(R.id.textViewAddictionDetails);
tv_addiction_name.setText(cat_name);
tv_total = (TextView) findViewById(R.id.textview_total);
tv_today = (TextView) findViewById(R.id.textview_today);
tv_yesterday = (TextView) findViewById(R.id.textview_yesterday);
tv_this_week = (TextView) findViewById(R.id.textview_this_week);
tv_this_month = (TextView) findViewById(R.id.textview_this_month);
iv_back = (ImageView) findViewById(R.id.imageViewAddictionDetailsBack);
iv_back.setClickable(true);
iv_back.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(AddictionDetails.this, StartActivity.class);
startActivity(intent);
}
}
);
iv_filter = (ImageView) findViewById(R.id.imageViewAddictionDetailsFilter);
iv_filter.setClickable(true);
iv_filter.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(state == false)
{
state = true;
popupView.setVisibility(View.VISIBLE); // Getting error on this line.