主にRPA、Androidアプリ開発について投稿しています。メモ書きです。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
public class SQLiteDBHelper extends SQLiteOpenHelper {コンストラクタを作成
public SQLiteDBHelper(Context context){OnCreateでTbl作成メソッドへ
super(context,DB_NAME,null,DB_VERSION);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
this.db = db;
createInputTbl();
createMasterTbl();
}
String createTbl_person =Activityでの呼び出しはこんな感じ
"CREATE TABLE " + "PERSON" + " ( " +
"ID" + " INTEGER PRIMARY KEY AUTOINCREMENT PRIMARY KEY, " +
"NAME" + " TEXT NOT NULL, " +
"AGE" + " INTEGER, " +
"DATE_ADDED" + "TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL" +
")";
db.execSQL(createTbl_person);
SQLiteDBHelper helper = new SQLiteDBHelper(this);
SQLiteDatabase db = helper.getReadableDatabase();
登録データContentValues values = new ContentValues();
values.put(nameColumn[0],data[0]);insert
helper.insertTbl(db,"PERSON",values);closeをわすれずに
db.close();
dbの削除はこんな感じthis.deleteDatabase(helper.getDatabaseName());
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>それでも変わらぬ
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
public static String[] getExternalStorageDirectories(Context context) {https://akira-watson.com/android/sdcard_path.html
List<String> results = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
File[] externalDirs = context.getExternalFilesDirs(null);
for (File file : externalDirs) {
String path = file.getPath().split("/Android")[0];
boolean addPath = false;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
addPath = Environment.isExternalStorageRemovable(file);
}
else{
addPath = Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(file));
}
if(addPath){
results.add(path);
}
}
}
if(results.isEmpty()) {
String output = "";
try {
final Process process = new ProcessBuilder().command("mount | grep /dev/block/vold")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
output = output + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
if(!output.trim().isEmpty()) {
String devicePoints[] = output.split("\n");
for(String voldPoint: devicePoints) {
results.add(voldPoint.split(" ")[2]);
}
}
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (int i = 0; i < results.size(); i++) {
if (!results.get(i).toLowerCase().matches(".*[0-9a-f]{4}[-][0-9a-f]{4}")) {
results.remove(i--);
}
}
} else {
for (int i = 0; i < results.size(); i++) {
if (!results.get(i).toLowerCase().contains("ext") && !results.get(i).toLowerCase().contains("sdcard")) {
results.remove(i--);
}
}
}
String[] storageDirectories = new String[results.size()];
for(int i=0; i<results.size(); ++i) storageDirectories[i] = results.get(i);
return storageDirectories;
}
if (bundle == null) {
activity.getSupportFragmentManager().beginTransaction()
.add(R.id.keyContainer, new TenkeyFragment())
.commit();
TextView.OnClickListener OnClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
getFragmentManager().beginTransaction().remove(SiteInfoFragment.this).commit();
//または
getFragmentManager().popBackStack();
}
};
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if(convertView ==null) {
convertView = getGenericView(0);
}
TextView tvSiteName = convertView.findViewById(R.id.tvSiteName);
tvSiteName.setText(groups.get(groupPosition));
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ExpandableListView elv = (ExpandableListView)parent;
if(!elv.isGroupExpanded(groupPosition)) {
GradientDrawable gd = new GradientDrawable();
gd.setColor(context.getColor(R.color.colorTkmtGreen));
convertView.setForeground(gd);
}else{
convertView.setForeground(null);
}
ExpandableListView.OnGroupClickListener OnGroupClickInput = new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
System.out.println(parent.getAdapter().getClass().getSimpleName());
System.out.println(parent.getExpandableListAdapter().getClass().getSimpleName());
I/System.out: ExpandableListConnectorgetExpandableListAdapter()とする必要がある。
ExpandableTkmtAdapter
ExpandableListView.OnGroupCollapseListener OnGroupCollapseInput = new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
ExpandableListView elvHis = findViewById(R.id.elvHistory);
if(elvHis.isGroupExpanded(groupPosition)) {
elvHis.collapseGroup(groupPosition);
}
}
};
ExpandableListView.OnGroupExpandListener OnGroupExpandInput = new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
ExpandableListView elvHis = findViewById(R.id.elvHistory);
if(!elvHis.isGroupExpanded(groupPosition)) {
elvHis.expandGroup(groupPosition);
}
}
};
ExpandableListView.OnGroupCollapseListener OnGroupCollapseHistory = new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
ExpandableListView elvInput = findViewById(R.id.elvInput);
if(elvInput.isGroupExpanded(groupPosition)) {
elvInput.collapseGroup(groupPosition);
}
}
};
ExpandableListView.OnGroupExpandListener OnGroupExpandHistory = new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
ExpandableListView elvInput = findViewById(R.id.elvInput);
if(!elvInput.isGroupExpanded(groupPosition)) {
elvInput.expandGroup(groupPosition);
}
}
};
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="0"
android:toXDelta="10%"
android:repeatMode="reverse"
android:repeatCount="-1"
/>
</set>
ImageView img = findViewById(R.id.imgOh);
img.startAnimation(AnimationUtils.loadAnimation(this, R.anim.a1));