package com.adamschardt.hauling;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
private static final int NUM_PAGES = 5;
private ViewPager mPager;
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new MyFragmentStatePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
@Override
public void onBackPressed() {
if (mPager.getCurrentItem() == 0) {
super.onBackPressed();
} else {
mPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
}
private class MyFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
public MyFragmentStatePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment tmpFragment;
if(position==4){
tmpFragment = new SlidePageSupportFragment4();
}else{
tmpFragment = new SlidePageSupportFragment();
((SlidePageSupportFragment)tmpFragment).setPageNumber(position);
}
return tmpFragment;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
EditText fcontent,fcontent2,fcontent3,fcontent4,fname;
Button write;
protected void onCreate2(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide_page);
fname = (EditText)findViewById(R.id.fname);
fcontent = (EditText)findViewById(R.id.edit);
fcontent2 = (EditText)findViewById(R.id.edit2);
fcontent3 = (EditText)findViewById(R.id.edit3);
fcontent4 = (EditText)findViewById(R.id.edit4);
write = (Button)findViewById(R.id.btnwrite);
write.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String filename = fname.getText().toString();
String filecontent = fcontent.getText().toString();
String filecontent2 = fcontent2.getText().toString();
String filecontent3 = fcontent3.getText().toString();
String filecontent4 = fcontent4.getText().toString();
FileOperations fop = new FileOperations();
fop.write(filename, filecontent, filecontent2, filecontent3, filecontent4, filecontent4);
if(fop.write(filename, filecontent, filecontent2, filecontent3, filecontent4, filecontent4)){
Toast.makeText(getApplicationContext(), filename+".txt created", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "I/O error", Toast.LENGTH_SHORT).show();
}
}
});
}
}
我無法寫入我的SD卡。事實上,寫入按鈕不會做任何事情。我是否正確啓動了它?我的代碼錯了嗎?我的logcat沒有任何幫助:/任何幫助,將不勝感激班級不會寫入我的SD卡
我不確定是否因爲我使用視圖尋呼機?
您的代碼可能是正確的,但現在,你已經設置AndroidManifest安全權限,只是谷歌它:-) – 2015-02-07 01:34:14
我覺得你的Android文件I/O操作是不恰當的SD卡。也許上傳你的類FileOperations。稍後我會發佈一個我認爲會幫助你的答案。保持發佈到您的進度。 – 2015-02-09 02:57:40
如果您認爲您的問題可能出現在SD或文件I/O中,請在您的問題中添加另一個(更恰當的)標記,然後刪除android-fragments作爲問題。 – 2015-02-09 02:59:06