我想dp从px编程上计算.怎么做?我得到的答案是:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
ht = displaymetrics.heightPixels;
wt = displaymetrics.widthPixels;
Run Code Online (Sandbox Code Playgroud) 我希望以hh:mm格式显示两次之间的差异.
第一次是来自数据库,第二次是系统时间.时差每秒更新一次.
我怎样才能做到这一点?
目前我正在使用两个手动时间如果这完全有效,那么我将它实现到我的应用程序中.
public class MainActivity extends Activity
{
TextView mytext;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Timer updateTimer = new Timer();
updateTimer.schedule(new TimerTask()
{
public void run()
{
try
{
TextView txtCurrentTime= (TextView)findViewById(R.id.mytext);
SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss aa");
Date date1 = format.parse("08:00:12 pm");
Date date2 = format.parse("05:30:12 pm");
long mills = date1.getTime() - date2.getTime();
Log.v("Data1", ""+date1.getTime());
Log.v("Data2", ""+date2.getTime());
int hours = (int) (mills/(1000 * 60 * 60));
int mins = (int) (mills % (1000*60*60));
String …Run Code Online (Sandbox Code Playgroud) 我正在尝试在项目中配置Checkstyle.我已经添加:
apply plugin: 'checkstyle'
checkstyle {
// assign the latest checkstyle version explicitly
// default version is very old, likes 5.9
toolVersion = '8.6'
// checkstyle.xml copy from:
// https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-8.6/src/main/resources/google_checks.xml
// the version should be as same as plugin version
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
}
task Checkstyle(type: Checkstyle) {
source 'src/main/java'
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'
// empty classpath
classpath = rootProject.files()
}
Run Code Online (Sandbox Code Playgroud)
到我的根gradle文件中allprojects.
但是当我跑步的时候 ./gradlew checkstyle
我明白了:
* What went wrong:
Execution failed for task …Run Code Online (Sandbox Code Playgroud) 我有这样的Parcelable枚举:
public enum Option implements Parcelable {
DATA_BASE, TRIPS, BIG_PHOTOS,
OLD_PHOTOS, FILTERS_IMAGES,
CATEGORIES_IMAGES, PAGES,
SOUNDS, PUBLIC_TRANSPORT, MAPS;
public static final Parcelable.Creator<Option> CREATOR = new Parcelable.Creator<Option>() {
public Option createFromParcel(Parcel in) {
return Option.values()[in.readInt()];
}
public Option[] newArray(int size) {
return new Option[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(ordinal());
}
}
Run Code Online (Sandbox Code Playgroud)
现在我修改了它,它看起来像:
public enum Option implements Parcelable {
DATA_BASE("Database"), TRIPS("Trips"), BIG_PHOTOS("BigPhotos"),
OLD_PHOTOS("OldPhotos"), FILTERS_IMAGES("FiltersImages"),
CATEGORIES_IMAGES("CategoriesImages"), PAGES("Pages"),
SOUNDS("Sounds"), PUBLIC_TRANSPORT("PublicTransport"), MAPS("Maps"); …Run Code Online (Sandbox Code Playgroud) 我为spinner扩展了ArrayAdapter:
class OrderAdapter(context: Context, resource: Int, objects: List<Order>) : ArrayAdapter<Order>(context, resource, objects) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
val view = super.getView(position, convertView, parent)
view?.let { view.find<TextView>(android.R.id.text1).text = getItem(position).name }
return view
}
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View? {
val view = super.getDropDownView(position, convertView, parent)
view?.let {view.find<TextView>(android.R.id.text1).text = getItem(position).name }
return view
}
}
Run Code Online (Sandbox Code Playgroud)
我得到例外:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
at com.github.blabla.endlesss.ui.adapter.OrderAdapter.getView(OrderAdapter.kt:0)
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决它?
我刚刚将 DataStore 添加到我们的代码库中。之后,我发现所有顺序 UI 测试都失败 - 测试用例中的第一个测试通过,但下一个失败并显示There are multiple DataStores active for the same file.
我使用 Hilt 提供一个数据存储实例
\n@InstallIn(SingletonComponent::class)\n@Module\ninternal object DataStoreModule {\n\n @Singleton\n @Provides\n internal fun provideConfigurationDataStore(\n @ApplicationContext context: Context,\n configurationLocalSerializer: ClientConfigurationLocalSerializer\n ): DataStore<ClientConfigurationLocal> = DataStoreFactory.create(\n serializer = configurationLocalSerializer,\n produceFile = { context.dataStoreFile("configuration.pb") }\n )\n}\nRun Code Online (Sandbox Code Playgroud)\n我猜这是因为In a Hilt test, the singleton component\xe2\x80\x99s lifetime is scoped to the lifetime of a test case rather than the lifetime of the Application.
关于如何解决这个问题有什么想法吗?
\n我正在尝试在数据绑定中使用算术运算:
<Space
android:layout_width="match_parent"
android:layout_height="@{2 * @dimen/button_min_height}" />
Run Code Online (Sandbox Code Playgroud)
不幸的是我得到了:
Error:(47, 47) must be able to find a common parent for int and float
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在通过菜单将SearchView添加到我的工具栏:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search_white"
android:orderInCategory="0"
android:title="@android:string/search_go"
android:visible="true"
app:actionViewClass="android.support.v7.widget.SearchView"
app:iconifiedByDefault="false"
app:showAsAction="always" />
</menu>
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会发生这种情况?
我想使用setClicable()使按钮无法点击但它不起作用.我正在使用inflater,因为我需要.这是我的代码:
mContactList = (LinearLayout) findViewById(R.id.contactList);
LayoutInflater inflater = getLayoutInflater();
for (ListIterator<ContactModel> it = contactList.listIterator(); it.hasNext();){
ContactModel contact = it.next();
View view = inflater.inflate(R.layout.contact_unknown_list_row, null);
view.findViewById(R.id.inviteButton).setTag(contact.getEmail());
view.findViewById(R.id.inviteButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String address = (String) v.getTag();
sendInvatoin(address);
if(v.findViewById(R.id.inviteButton).isClickable())
v.findViewById(R.id.inviteButton).setClickable(false);
}
});
mContactList.addView(view);
}
Run Code Online (Sandbox Code Playgroud) 我想使用内容提供程序删除第一个"n"行.
这是我的代码:
private void deleteOldItems(int number) {
String where = HistoryTable.COLUMN_ID + "<=?";
getContentResolver()
.delete(Uri.parse("content://com.ipiit.client.contentprovider.HistoryContentProvider/histories"),
where, new String[] {String.valueOf(number)});
}
Run Code Online (Sandbox Code Playgroud)
我工作但只有一次.如何始终删除第一行?
android ×10
layout ×2
button ×1
checkstyle ×1
dagger-hilt ×1
datastore ×1
enums ×1
java ×1
kotlin ×1
menu ×1
parcelable ×1
resolution ×1
searchview ×1
sqlite ×1
time ×1
view ×1