我是数据绑定的新手,这是我的代码,但在构建时出现此错误
class DatabindingViewModel :ViewModel() {
val currentFruitName:LiveData<String>
get() = FakeRepository.currentName
fun changeNameOnClick()=FakeRepository.changeRandomFoodName()
//two way LiveData
@Bindable
val editTextContext= MutableLiveData<String>()
private val _displayEditTexfContent=MutableLiveData<String>()
val displayEditTexfContent:LiveData<String>
get()=_displayEditTexfContent
fun onDisplayEtText(){
_displayEditTexfContent.value=editTextContext.value
}
Run Code Online (Sandbox Code Playgroud)
这是我的 xml 布局代码:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="binding"
type="ir.persiandesigners.myapplication.databinding.viewmodel.DatabindingViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:text="@{binding.currentFruitName}"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:onClick="@{()->binding.changeNameOnClick()}"
android:text="Get Random Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/editText" …Run Code Online (Sandbox Code Playgroud) 很奇怪为什么 fontFamily 不能在 androidX 上工作。
这是我的代码:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="testing "
android:textSize="17sp"
android:fontFamily="@font/iransans"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)
上面的代码根本不影响字体,当我将 textview 转换为 app compact 时,它可以工作:
<androidx.appcompat.widget.AppCompatTextView
Run Code Online (Sandbox Code Playgroud)
我想设置我的整个应用程序字体,但它不像我预期的那样工作:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/iransans</item>
</style>
Run Code Online (Sandbox Code Playgroud)
有什么办法可以解决这个问题吗?如何在不为每个视图设置字体系列的情况下在整个应用程序中使用我的字体?
我有一个关于我的活动的列表视图,当我到达listview的末尾时,它调用async并使用json获取新数据.这是async和baseAdaper代码:
ListAdapter ladap;
private class GetContacts AsyncTask<Void, Void,ArrayList<HashMap<String, String>>> {
@Override
protected Void doInBackground(Void... arg0) {
Spots_tab1_json sh = new Spots_tab1_json();
String jsonStr = sh.makeServiceCall(url + page, Spots_tab1_json.GET);
ArrayList<HashMap<String, String>> dataC = new ArrayList<HashMap<String, String>>();
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
contacts = jsonObj.getJSONArray(TAG_CONTACTS);
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String id = new String(c.getString("id").getBytes("ISO-8859-1"), "UTF-8");
String dates = new String(c.getString("dates").getBytes("ISO-8859-1"), "UTF-8");
String price = new …Run Code Online (Sandbox Code Playgroud) 我在 api 26 中的启动器图标有一个大问题
我有透明背景的png,但它在透明部分变黑
这是结果:
这不是主题,因为其他应用程序没有背景
这是我的清单:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
这是 api 26 的代码
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
Run Code Online (Sandbox Code Playgroud)
这是 ic_launcher_background 文件,它是一个透明图像:
这是 ic_launcher_foreground 文件:
我该如何解决这个问题?我怎样才能摆脱黑色背景?
我已将 SDK 版本更新为 31,之后出现此错误。这是我的摇篮:
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.persiandesigners.alldentshops"
minSdkVersion 16
targetSdkVersion 31
vectorDrawables.useSupportLibrary = true
versionCode 1
versionName "1"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0-alpha01'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
Run Code Online (Sandbox Code Playgroud)
我收到此错误:清单合并失败:需要显式指定 android:exported for 。android:exported当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。
我按照它说的做了,这是我的清单代码:
<activity
android:name="mypackage.MainActivity"
android:exported="true"
tools:node="merge"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/SplashScreenTheme"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" …Run Code Online (Sandbox Code Playgroud) 可能重复:
Android 删除查询
我有 db,现在它有 17 条记录。这是我的代码:
SQLiteDatabase db=openOrCreateDatabase("mydb", MODE_PRIVATE, null);
c= db.rawQuery("DELETE FROM tbl1 where cat='12'",null);
db.close();
Run Code Online (Sandbox Code Playgroud)
这是一个非常简单的查询,但是每次我在模拟器上运行该应用程序时,它都会完美运行而没有任何错误,但我也没有删除任何内容。
任何人都可以帮助我解决问题吗?
我收到此错误:java.lang.IllegalStateException:适配器的内容已更改但ListView未收到通知.确保不从后台线程修改适配器的内容,而只是从UI线程修改.[在ListView(2131034188,类android.widget.ListView)中使用Adapter(类.MainActivity $ ListAdapter)]
这就是我做的,我运行一个AsyncTask并获取json数据,然后,onPostExecute,我调用ListAdapter将数据转换为listview.
@Override
protected Void doInBackground(Void... arg0) {
Spots_tab1_json sh = new Spots_tab1_json();
String jsonStr = sh.makeServiceCall(url + page, Spots_tab1_json.GET);
if (jsonStr != null) {
JSONObject jsonObj = new JSONObject(jsonStr);
contacts = jsonObj.getJSONArray(TAG_CONTACTS);
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String onvan = new String(c.getString("onvan").getBytes("ISO-8859-1"), "UTF-8");
String id = new String(c.getString("id").getBytes("ISO-8859-1"), "UTF-8");
String dates = new String(c.getString("dates").getBytes("ISO-8859-1"), "UTF-8");
String price = new String(c.getString("gheymat").getBytes("ISO-8859-1"), "UTF-8");
HashMap<String, String> contact = new HashMap<String, String>(); …Run Code Online (Sandbox Code Playgroud) 我的代码中有一个浮点数据,我需要从中获取字符串.问题是,当我有像10000000这样的大数字时,它将数字转换为这样的数字:1.0E7
如何将其转换为实际数字?
我连接了 genymotion 模拟器和我的手机,我想通过 wifi 运行和调试我的应用程序,我找到了这样做的说明,但是当我输入此代码时出现此错误:
adb tcpip 5555
Run Code Online (Sandbox Code Playgroud)
我收到此错误:错误:不止一个设备/模拟器
我怎样才能让我的设备成为默认设备或类似的东西来解决这个问题?
我在我的应用程序中使用 Retrofit 2 和 rxjava 2。这些是我的 gradle 实现:
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
Run Code Online (Sandbox Code Playgroud)
这是我的 API 连接类:
public class ApiConnection {
private static String BaseUrl = "http://mysites.com/";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
Gson gson = new GsonBuilder()
.setLenient()
.create();
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BaseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
}
Run Code Online (Sandbox Code Playgroud)
我在这一行遇到错误:
RxJava2CallAdapterFactory
Run Code Online (Sandbox Code Playgroud)
这是错误:
Cannot resolve symbol 'RxJava2CallAdapterFactory
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题吗?
我是kotlin的新手,这是我的适配器代码,可以正常工作,并且我没有问题,现在,我需要为其实现点击监听器,这是我的代码:
class CategoryAdapter(val context: Context,val list: List<CategoryItems>): RecyclerView.Adapter<CategoryAdapter.ViewHolder>() {
var typeface: Typeface? = Func.getTypeFace(context)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
var catRow=list.get(position)
holder?.tvTitle.text = catRow.name
holder?.tvTitle.setTypeface(typeface)
Glide.with(context).load(Const.BaseUrl+"Opitures/"+ catRow.icon_name).into(holder?.imgCat);
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent?.context).inflate(R.layout.category_item, parent, false)
return ViewHolder(v);
}
override fun getItemCount(): Int {
return list.size
}
class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
val tvTitle = itemView.findViewById<TextView>(R.id.tv_cat_title)
val imgCat = itemView.findViewById<ImageView>(R.id.img_cat)
}
}
Run Code Online (Sandbox Code Playgroud)
我想添加点击侦听器,我曾经在实现点击侦听器的viewholder类中这样做
如何在Kotlin中做到这一点?我绑了很多路但没有成功
android ×11
android-12 ×1
androidx ×1
java ×1
kotlin ×1
retrofit2 ×1
rx-java2 ×1
sql-delete ×1
sqlite ×1