我一直在尝试从SQLite数据库中获取所有行.但是我从下面的代码中得到了最后一行.
FileChooser类:
public ArrayList<String> readFileFromSQLite() {
fileName = new ArrayList<String>();
fileSQLiteAdapter = new FileSQLiteAdapter(FileChooser.this);
fileSQLiteAdapter.openToRead();
cursor = fileSQLiteAdapter.queueAll();
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
fileName.add(cursor.getString(cursor.getColumnIndex(FileSQLiteAdapter.KEY_CONTENT1)));
} while (cursor.moveToNext());
}
cursor.close();
}
fileSQLiteAdapter.close();
return fileName;
}
Run Code Online (Sandbox Code Playgroud)
FileSQLiteAdapter类:
public Cursor queueAll() {
String[] columns = new String[] { KEY_ID, KEY_CONTENT1 };
Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null,
null, null, null, null);
return cursor;
}
Run Code Online (Sandbox Code Playgroud)
请告诉我,我的错误在哪里.欣赏.
我使用这两个onClickListener和onLongClickListener一个TextView的在ListView控件.我看到在Android 1.6中,长时间点击监听器与点击监听器一起被激活,这意味着当我长按时,两者都被触发.但在未来的版本中并非如此.有没有解决这个问题?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.row, parent, false);
}
TextView tv = (TextView) row.findViewById(R.id.tv);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showMessage();
}
});
tv.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showLongMessage();
}
});
}
Run Code Online (Sandbox Code Playgroud) 这里我的代码我在下面的代码中使用它们的纬度和经度来计算两个位置之间的距离.这是错误的距离.有时候变得正确,有时会变得无关紧要.
我们从数据库获取lat1和lng1.
//getting lat2 and lng2 from GPS as below
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc)
{
lat2=loc.getLatitude();
lng2=loc.getLongitude();
String Text = "My current location is: " +"Latitud = "+ loc.getLatitude() +"Longitud = " + loc.getLongitude();
//System.out.println("Lat & Lang form Loc"+Text);
//Toast.makeText( getApplicationContext(), Text,Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider)
{
}
@Override
public void onProviderEnabled(String provider)
{
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
//Calculating distance
double earthRadius = …Run Code Online (Sandbox Code Playgroud) 我想传递来自另一个活动的一个活动的对象列表.我在下面有一个类SharedBooking:
public class SharedBooking {
public int account_id;
public Double betrag;
public Double betrag_effected;
public int taxType;
public int tax;
public String postingText;
}
Run Code Online (Sandbox Code Playgroud)
来自呼叫活动的代码:
public List<SharedBooking> SharedBookingList = new ArrayList<SharedBooking>();
public void goDivision(Context context, Double betrag, List<SharedBooking> bookingList) {
final Intent intent = new Intent(context, Division.class);
intent.putExtra(Constants.BETRAG, betrag);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
被叫活动的代码:
Bundle extras = getIntent().getExtras();
if (extras != null) {
amount = extras.getDouble(Constants.BETRAG,0);
}
Run Code Online (Sandbox Code Playgroud)
如何从一个活动发送SharedBooking列表并在其他活动中接收该列表?
请建议我任何可用的链接或示例代码.
对这个重复的问题道歉,但我还没有找到任何令人满意的答案.大多数问题都有自己的特定用例:
Java -
thread.sleep的替代方法是否有更好的或替代方法可以跳过/避免在Java中使用Thread.sleep(1000)?
我的问题是非常通用的用例.等待条件完成.做一些操作.检查条件.如果条件不成立,请等待一段时间再进行相同的操作.
例如,考虑一种通过调用其createAPI表来创建DynamoDB表的方法.DynamoDB表需要一些时间才能变为活动状态,因此该方法会调用其DescribeTable API以定期轮询状态,直到某个时间(假设5分钟 - 由于线程调度而导致的偏差是可接受的).如果表在5分钟内变为活动状态,则返回true,否则抛出异常.
这是伪代码:
public void createDynamoDBTable(String name) {
//call create table API to initiate table creation
//wait for table to become active
long endTime = System.currentTimeMillis() + MAX_WAIT_TIME_FOR_TABLE_CREATE;
while(System.currentTimeMillis() < endTime) {
boolean status = //call DescribeTable API to get status;
if(status) {
//status is now true, return
return
} else {
try {
Thread.sleep(10*1000);
} catch(InterruptedException e) {
}
}
}
throw new RuntimeException("Table still not created");
}
Run Code Online (Sandbox Code Playgroud)
我理解通过使用Thread.sleep块当前线程,从而消耗资源.但是在一个相当中等规模的应用程序中,一个主题是一个大问题吗?
我在那里阅读使用 …
该应用程序具有启用了多选的ListView,在UI中按预期工作.但是当我使用此代码读取值时:
Log.i(TAG,"Entered SearchActivity.saveCategoryChoice()");
SparseBooleanArray checkedPositions = categorySelector.getCheckedItemPositions();
Log.i(TAG,"checkedPositions: " + checkedPositions.size());
if (checkedPositions != null) {
int count = categoriesAdapter.getCount();
for ( int i=0;i<count;i++) {
Log.i(TAG,"Selected items: " + checkedPositions.get(i));
}
}
Run Code Online (Sandbox Code Playgroud)
无论每个复选框处于什么状态,我都会得到此输出:
Entered SearchActivity.saveCategoryChoice()
checkedPositions: 0
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: false
Selected items: …Run Code Online (Sandbox Code Playgroud) 我认为singleLine="true"相当于maxLines="1"但我看到Android Studio中的以下预先填充的字段都有.有区别吗?是否存在导致两者都需要的已知错误?
<EditTextPreference
android:key="example_text"
android:title="@string/pref_title_display_name"
android:defaultValue="@string/pref_default_display_name"
android:selectAllOnFocus="true"
android:inputType="textCapWords"
android:capitalize="words"
android:singleLine="true"
android:maxLines="1" />
Run Code Online (Sandbox Code Playgroud)
这是来自pref_general.xml文件.
我收到这个错误.尽管尝试了所有的事情我无法解决它.请帮我.
我尝试过的事情是:
.build,.idea等再重建谢谢
插件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
Run Code Online (Sandbox Code Playgroud)
Android的
android {
dexOptions {
preDexLibraries = false
javaMaxHeapSize "2g"
}
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.funzone.alarmnap"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
multiDexEnabled true
versionName "1.1"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Run Code Online (Sandbox Code Playgroud)
Greendao插件
apply plugin: 'org.greenrobot.greendao'
greendao {
targetGenDir 'src/main/java'
schemaVersion 2 …Run Code Online (Sandbox Code Playgroud) 我无法通过新项目从jcenter获得kotlin pom。
我所要做的就是走File-> New Project并创建一个没有活动的新项目。
尝试构建时出现以下错误:
ERROR: Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.21/kotlin-stdlib-jdk8-1.3.21.pom'. Received status code 502 from server: Bad Gateway Enable Gradle 'offline mode' and sync project
Run Code Online (Sandbox Code Playgroud)
我的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
} …Run Code Online (Sandbox Code Playgroud) 我的项目目前正在使用,但似乎我已经转移到api 26级 - 修订版26.0.2,我正在努力寻找符号 KeyEventCompat
import android.support.v4.view.KeyEventCompat;
Run Code Online (Sandbox Code Playgroud)
我试图找出使用v7但它不起作用.任何关于如何使其工作的想法.
使用示例:
case KeyEvent.KEYCODE_TAB:
if (KeyEventCompat.hasNoModifiers(event)) {
handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
handled = arrowScroll(FOCUS_BACKWARD);
}
break;
Run Code Online (Sandbox Code Playgroud)
任何关于如何使其工作的想法.
谢谢