MainActivity中的this是什么public class MainActivity extends Activity {\x05private static final String TAG = "MainActivity";private FileService fileService;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceStat

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 01:59:59
MainActivity中的this是什么publicclassMainActivityextendsActivity{\x05privatestaticfinalStringTAG="MainAct

MainActivity中的this是什么public class MainActivity extends Activity {\x05private static final String TAG = "MainActivity";private FileService fileService;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceStat
MainActivity中的this是什么
public class MainActivity extends Activity {
\x05private static final String TAG = "MainActivity";
private FileService fileService;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fileService = new FileService(this);
Button button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
\x05\x05\x05@Override
\x05\x05\x05public void onClick(View v) {
\x05\x05\x05\x05EditText filenameText = (EditText) findViewById(R.id.filename);
\x05\x05\x05\x05EditText contentText = (EditText) findViewById(R.id.filecontent);
\x05\x05\x05\x05String filename = filenameText.getText().toString();
\x05\x05\x05\x05String content = contentText.getText().toString();
\x05\x05\x05\x05try {
\x05\x05\x05\x05\x05//判断sdcard是否存在于手机上,并且可以进行读写访问
\x05\x05\x05\x05\x05if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
\x05\x05\x05\x05\x05\x05fileService.saveToSDCard(filename,content);
\x05\x05\x05\x05\x05\x05Toast.makeText(MainActivity.this,R.string.success,1).show();
\x05\x05\x05\x05\x05}else{
\x05\x05\x05\x05\x05\x05Toast.makeText(MainActivity.this,R.string.sdcarderror,1).show();
\x05\x05\x05\x05\x05}
\x05\x05\x05\x05} catch (Exception e) {
\x05\x05\x05\x05\x05Log.e(TAG,e.toString());
\x05\x05\x05\x05\x05Toast.makeText(MainActivity.this,R.string.error,1).show();
\x05\x05\x05\x05}
\x05\x05\x05}
\x05\x05});
}
}
上面fileService = new FileService(this);中的this什么意思

MainActivity中的this是什么public class MainActivity extends Activity {\x05private static final String TAG = "MainActivity";private FileService fileService;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceStat
this就是获得当前对象,在你的程序里就是获得MainActivity这个对象.你改成MainActivity.this也可以的