我正在开发一个面向群组的网络应用程序.问题是,当我即将加入一个组时,它首先检查该组是否安全,如果是,它会询问用户和密码.获得组安全性可能需要几秒钟,因此我为整个过程生成了一个新线程.如果该组需要安全性,我想弹出一个Dialog.我认为它可能与后台线程有关,它们可能无法弹出Dialogs ......但问题是我需要在后台线程中检查组安全性,因为它需要一些时间.
希望任何人都可以提出解决方案或任何方式只在组安全时询问用户/通过.这是后台主题:
public void run() {
secInf = mGroupId.getSecurityInformation();
if (secInf.getAdmissionLevel() == CreateGroupDialog.PRIVATE_KEY_ACCESS) {
showUserPasswordDialog();
} else {
mService.joinGroup(mGroupId);
// Notifies handler to dismiss ProgresDialog and start activity
mHandler.sendMessage(Message.obtain(mHandler,
GroupsActivity.JOIN_SUCCESSFUL));
}
Run Code Online (Sandbox Code Playgroud)
showUserPasswordDialog的用途(mActivity是产生此线程的活动):
private void showUserPasswordDialog() {
AlertDialog dialog;
// add this to your code
// This example shows how to add a custom layout to an AlertDialog
LayoutInflater factory = LayoutInflater.from(mActivity);
final View textEntryView = factory.inflate(
R.layout.alert_dialog_text_entry, null);
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setIcon(R.drawable.alert_dialog_icon);
builder.setTitle(R.string.ask_user_password);
builder.setView(textEntryView);
builder.setPositiveButton(R.string.ok_text,
new DialogInterface.OnClickListener() …Run Code Online (Sandbox Code Playgroud) 尝试使用片段显示Google地图.使用以下页面作为教程.
我得到异常"错误膨胀类片段".
1)导入jar google-play-services.jar
2)下载并配置了google play services SDK.
3)获得最新的v2 API密钥.
4)在清单中添加了com.google.android.providers.gsf.permission.READ_GSERVICES权限.
5)使用mindsdk = 8和target = 16.
供参考,Androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.mapsdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<permission
android:name="com.example.com.mapsdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.com.mapsdemo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.com.mapsdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDXPsxWF634gd907NzZKkRkNS0oH9IPWgk"/>
</application>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
package com.example.com.mapsdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu; …Run Code Online (Sandbox Code Playgroud) 我有一个模板视图,它看起来像;
template.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/view_background"
android:gravity="center_vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/btnMultiple"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@drawable/button_backgroundblue"
android:onClick="btnMultiple_clicked"
android:tag="4"
android:text="@string/mc_abcd"
android:textColor="@drawable/button_textcolor"
android:textSize="@dimen/h2" />
Run Code Online (Sandbox Code Playgroud)
我正在以编程方式创建此视图,然后我将此视图添加到ViewFlipper中;
activity_main.java
public void btnCreateView_clicked(View view) {
ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
View myView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.template, viewFlipper, false);
viewFlipper.addView(myView);
viewFlipper.showNext(); // Showing lastly created myView successfully. }
Run Code Online (Sandbox Code Playgroud)
我的活动也有公共功能;
activity_main.java
public void btnMultiple_clicked(View view) {
//Save the world !
}
Run Code Online (Sandbox Code Playgroud)
当我按下从第一个视图它的成功创建模板(MyView的),然后将其添加到ViewFlipper btnCreateView按钮.当我点击btnMultiple我收到错误,我的应用程序崩溃; "无法在活动类android.app.Application中找到方法btnMultiple_clicked(View),用于视图类android.widget.Button上的onClick处理程序,id为'btnMultiple'"我确定现有方法btnMultiple_clicked(View).
PS!如果我以编程方式将监听器添加到btnMultiple它会工作,但我想知道为什么"android:onClick ="btnMultiple_clicked""不起作用?
我RadioGroup用一个可变数量的radioButtons 做了一个.问题是可以检查许多radiobutton,它不是一个单一的RadioButton检查RadioGroup(据我所知)我的错误在哪里?这是我的代码:
View view = inflater.inflate(R.layout.questionnaire_check_question, null);
RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup);
for (int k = 0; k < answerValues.size(); k++) {
View radioButtonView = inflater.inflate(R.layout.check_radio_button, null);
RadioButton radioButton = (RadioButton) radioButtonView
.findViewById(R.id.radio_button);
radioButton.setText(answerValues.get(k));
radioGroup.addView(radioButtonView);
}
questionBody.addView(view);
Run Code Online (Sandbox Code Playgroud)
questionnaire_check_question.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#A4A7A6" >
<RadioGroup
android:id="@+id/radioGroup"
android:scrollbars="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</RadioGroup>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
check_radio_button.xml
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/radio_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:button="@drawable/checkbox"
>
</RadioButton>
Run Code Online (Sandbox Code Playgroud)
绘制/ checkbox.xml
<?xml …Run Code Online (Sandbox Code Playgroud) android.view.InflateException: Binary XML file line #6: Error inflating class fragment
Run Code Online (Sandbox Code Playgroud)
我试图在各种教程之后的片段中实现Google Map apiv2,我遇到错误膨胀类片段,然后我在stackoverflow遇到了各种类似的问题,尝试了几乎所有问题,但问题仍然存在.我是android的新手,欢迎任何类型的提示,我想快速学习android开发,但我被卡住了.提前致谢.
编辑:当我从片段3转到片段2并且片段1在后台加载时,应用程序意外关闭.有什么想法可以解决这些问题?
我的android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hspot2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<permission
android:name="com.example.hspot2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.hspot2.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data …Run Code Online (Sandbox Code Playgroud) 我的onCreateOptionsMenu作品仅在MainActivity中工作,当我尝试将另一个作品onCreateOptionsMenu放入另一个活动中以充实另一个菜单时,它不会显示菜单栏(请注意,我在两个活动中都将其设置完全相同)。
我没有收到任何错误,只是我的辅助活动上没有显示菜单栏。
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.expanded_view_layout);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
//noinspection SimplifiableIfStatement
int id = item.getItemId();
if (id == R.id.action_back) {
finish();
}
return super.onOptionsItemSelected(item);
}
Run Code Online (Sandbox Code Playgroud)
另请注意,我更改getMenuInflater()为super.getMenuInflater()并获得了相同的结果。
在尝试发布我的应用以进行生产时,预发布报告通知我 Pixel 2 Android P Preview 设备上出现错误。该错误与我拥有的自定义 Toast 消息有关,其中说“已将视图添加到窗口管理器”:
java.lang.IllegalStateException: View android.support.constraint.ConstraintLayout{efbeb21 V.E...... ......ID 0,0-788,1124 #7f0900db app:id/toast_correct_container} has already been added to the window manager.
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:328)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.widget.Toast$TN.handleShow(Toast.java:499)
at android.widget.Toast$TN$1.handleMessage(Toast.java:403)
at android.os.Handler.dispatchMessage(Handler.java:106)
at androidx.test.espresso.base.Interrogator.a(Interrogator.java:19)
at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:142)
at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:134)
at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:34)
at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:74)
at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:52)
at androidx.test.espresso.action.Tap.c(Tap.java:9)
at androidx.test.espresso.action.Tap.a(Tap.java:19)
at androidx.test.espresso.action.Tap$1.b(Tap.java:2)
at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:22)
at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:9)
at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:78)
at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:94)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) …Run Code Online (Sandbox Code Playgroud) I am working with two recyclerview in single screen(For android TV).Each recyclerview have complex layout item.And it's taking time to load.I worked with asynclayoutinflator in activities.
AsyncLayoutInflater inflater = new AsyncLayoutInflater(this);
inflater.inflate(R.layout.main, null, callback);
Run Code Online (Sandbox Code Playgroud)
I want to know whether there is any ways to achieve the same with recyclerview. Problem I am facing is onbindviewholder is getting called before asyncinflation finished.
android asynchronous android-inflate layout-inflater android-recyclerview
需要立即帮助!! 用来工作正常的代码,但过了一段时间我注意到评级没有t work anymore and gives "the specified child already has a parent, call removeView() first..." on thealertDialog.show();`line:
///// Rating bar initialising
Context mContext = ShowActivity.this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.custom_rate_dialog, (ViewGroup) findViewById(R.id.layout_root));
final RatingBar rating_indicator = (RatingBar)findViewById(R.id.rating_bar_cafe_indicator);
final float current_rating = (float)mDbHelper.getInt(mRowId, type, RATE_COLUMN);
rating_indicator.setRating(current_rating);
rateDialogBuilder = new AlertDialog.Builder(ShowActivity.this);
rateDialogBuilder.setView(layout);
rateDialogBuilder.setCancelable(false);
rateDialogBuilder.setIcon(R.drawable.rate_star_med_on);
rateDialogBuilder.setTitle("RATE IT!");
rateDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
rating_indicator.setRating(mDbHelper.getInt(mRowId, type, RATE_COLUMN));
((ViewGroup)layout.getParent()).removeView(layout);
dialog.cancel();
}
});
ratingText = …Run Code Online (Sandbox Code Playgroud) 我有 custom_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.example.MyCustomLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- different views -->
</com.example.MyCustomLayout>
Run Code Online (Sandbox Code Playgroud)
及其类别:
public class MyCustomLayout extends LinearLayout {
public MyCustomLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.custom_layout, this, true);
setUpViews();
}
//different methods
}
Run Code Online (Sandbox Code Playgroud)
和活动,其中包括以下布局:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
setUpViews();
}
Run Code Online (Sandbox Code Playgroud)
和 my_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.example.MyCustomLayout
android:id="@+id/section1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<com.example.MyCustomLayout
android:id="@+id/section2"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android ×10
android-inflate ×10
asynchronous ×1
dialog ×1
google-maps ×1
onclick ×1
radio-button ×1
radio-group ×1
view ×1
xml ×1