取不到已实现点击事件按钮的ID
这是什么错误?
这是什么错误?
2015-04-01
package com.demo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private Button button;
private Button button01;
private TextView textView ;
private EditText editText;
private ImageView imageView;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button) findViewById(R.id.button);
button01 = (Button) findViewById(R.id.button01);
textView = (TextView) findViewById(R.id.text_View);
editText = (EditText) findViewById(R.id.edit_Text);
imageView = (ImageView) findViewById(R.id.image_View);
progressBar = (ProgressBar) findViewById(R.id.progress_Bar);
button01.setOnClickListener(this);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
// case R.id.button:
// String inputText = editText.getText().toString(); //获取文本框 editText 中的内容存储在 inputText 中
// textView.setText(inputText); //把文本框中的内容输出在 textView 中
// Toast.makeText(MainActivity.this, inputText, Toast.LENGTH_SHORT).show(); //弹出 editText 中的内容
// imageView.setImageResource(R.drawable.background04); //单击 Button 按钮改变图片
// if (progressBar.getVisibility() == View.GONE) {
// progressBar.setVisibility(View.VISIBLE);
// }else {
// progressBar.setVisibility(View.GONE);
// }
// break;
case R.id.button01;
break;
default:
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
举报