Android開発
Android Studio 1.5 + Android SDK 23.0.1では、フラグメントを追加すると、MainActivityには、 import android.app.Fragmentだが、Fragmentクラスの方は、 import android.support.v4.app.Fragmentになっている。 そのせいで、Fragment#instantiateが、Inst…
X軸(時間軸)の目盛間隔を変えるサンプルコードです。 // X軸の目盛間隔を変える。DateAxis xAxis = (DateAxis)plot.getDomainAxis();xAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 2, new SimpleDateFormat("yyyy/MM")));
Y軸(値軸)の目盛間隔を変えるサンプルコードです。 XYPlot plot = chart.getXYPlot(); // Y軸の目盛間隔を変える。ValueAxis yAxis = plot.getRangeAxis();TickUnits ty = new TickUnits();TickUnit uniY = new NumberTickUnit(20);ty.add(uniY);yAxis.setSt…
グラフの4隅にマージンを持たせるサンプルコードです。 AFreeChart chart = ChartFactory.createTimeSeriesChart( "PV推移", "月", "PV", data, false, // ← 凡例無し false, false);// グラフの右側にマージンを持たせる。RectangleInsets insets = new Rec…
Y軸(値軸)のマーカーの設定のサンプルコードです。 // Y軸のマーカーの表示Marker marker = new ValueMarker(170);PaintType makerColor = new SolidColor(Color.rgb(180, 0, 180));marker.setPaintType(makerColor);marker.setStroke(2.0f);marker.setLabel…
凡例の消去のサンプルコードです。 AFreeChart chart = ChartFactory.createTimeSeriesChart( "PV推移", "月", "PV", data, false, // ← 凡例無し false, false); あるいは // 凡例の消去chart.removeLegend();
グラフタイトルのフォント指定 AFreeChart chart = ChartFactory.createTimeSeriesChart( "PV推移", "月", "PV", data, false, // ← 凡例無し false, false);// グラフのラベルを変えるTextTitle title = chart.getTitle();title.setFont(new Font(Typeface.…
軸のフォントの指定 XYPlot plot = chart.getXYPlot(); // 軸の目盛のフォントを変える。Font xyAxisFont = new Font(Typeface.SANS_SERIF, Typeface.BOLD, 30);plot.getRangeAxis().setTickLabelFont(xyAxisFont);plot.getDomainAxis().setTickLabelFont(xy…
1.グラフのViewを準備するクラス public class GraphView extends View { private AFreeChart chart; private RectShape chartArea; public GraphView(Context context, AttributeSet attrs) { super(context, attrs); chartArea = new RectShape(); } @Ov…
1.AFreeChartのダウンロード https://code.google.com/p/afreechart/downloads/list 上記URL から、 afreechart-0.0.4.jar をダウンロードし、プロジェクトのlibsフォルダに入れる。 2.build.gradleへの追加 dependencies { compile fileTree(dir: 'libs…
SQLiteの使い方:データベースの全消去のサンプルソースです。 mydb.delete("mytable", "_id like '%'", null); SQLiteの使い方:データベースの部分消去のサンプルソースです。 int delete(String table, String whereClause, String[] whereArgs); 引数tab…
final String columns = new String{“_id”,”bookmark”};String where = “bookmark like ?”;String param = “%android%”;Cursor c = sdb.query(“bookmarklist”,columns,where,new String[]{param},null,null,”_id desc”,”10″); SQLiteDatabase.query()メソッ…
SQLiteの使い方:Insertのサンプルソースコードです。 ContentValues values = new ContentValues();values.put("date", Register_date);values.put("weight", Weight);values.put("body_fat_percentage", BodyFatPercentage);long flag = mydb.insert("myta…
SQLiteの使い方:データベースのOpenのサンプルコードです。 public class MainActivity extends AppCompatActivity { static final String DB = "sqlite_sample.db"; static final int DB_VERSION = 1; static final String CREATE_TABLE = "create table m…
単純です。 finish(); あるいは getActivity().finish(); で終了できます。
EditTextのデータを、プリファレンスに設定する例です。 EditText edTextSettingName = (EditText) findViewById(R.id.editTextSettingName);String SettingName = edTextSettingName.getText().toString();EditText edTextMailAddress = (EditText) findVie…
下の例は、プリファレンスに保存していた情報を、メールツールに渡す暗黙的インテントの例です。 SharedPreferences prefs = getSharedPreferences("MailSetting01Activity", Context.MODE_PRIVATE);Resources res = getResources();String MailAddress = pr…
明示的インテントの使い方 Intent intent = new Intent(MainActivity.this, MailSetting01Activity.class);startActivity(intent); ここで、MainActivity.thisは遷移元のアクティビティ、MailSetting01Activity.classは遷移先のクラスです。
ボタンのOnClickListenerを作成する方法です。 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //…