我希望我的应用程序支持三种语言西班牙语,葡萄牙语和英语.并选择在app中选择语言.我已经做了
1)3个可绘制的文件夹drawable-es,drawable-pt,drawable.
2)3个值文件夹值-es,values-pt,values.根据语言更改String.xml值.
我有imageView来选择语言.当点击它打开菜单包括选项英语,西班牙语,葡萄牙语.
我通过此代码在选项选择中在应用程序内设置Locale
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.en:
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Toast.makeText(this, "Locale in English !", Toast.LENGTH_LONG).show();
break;
case R.id.pt:
Locale locale2 = new Locale("pt");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
Toast.makeText(this, "Locale in Portugal !", Toast.LENGTH_LONG).show();
break;
case R.id.es:
Locale locale3 = new Locale("es");
Locale.setDefault(locale3);
Configuration config3 = new Configuration();
config3.locale = locale3;
getBaseContext().getResources().updateConfiguration(config3, …
Run Code Online (Sandbox Code Playgroud) 我必须使用热敏打印机打印发票收据.我用Zjiang Thermal打印机打印收据.他们还提供手动和演示项目.在演示项目中,他们使用libray"btsdk.jar"来实现连接和打印.
我已成功建立打印机和Android设备之间的连接.但是没有文本对齐(中心,左,右)和单元格宽度,高度的准则.
我如何通过蓝牙打印机打印发票.
还请解释这一节 -
byte[] cmd = new byte[3];
cmd[0] = 0x1b;
cmd[1] = 0x21;
cmd[2] |= 0x10;
Run Code Online (Sandbox Code Playgroud)
cmd 2 - 用于更改字体高度使用cmd [0]和cmd 1
代码将打印消息发送到蓝牙打印机在演示项目中
String msg = "";
byte[] cmd = new byte[3];
cmd[0] = 0x1b;
cmd[1] = 0x21;
cmd[2] |= 0x10;
mService.write(cmd);
mService.sendMessage("Congratulations!\n", "GBK");
cmd[2] &= 0xEF;
mService.write(cmd);
msg = " You have sucessfully created communications between your device and our bluetooth printer.\n\n"
+" …
Run Code Online (Sandbox Code Playgroud) 我试图用Actionbarsherlock扩展我的活动,当我这样做时,我收到了一个错误
"无法覆盖SherlockActivity的最终方法"
我的活动有这些进口
import java.io.IOException;
import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
Run Code Online (Sandbox Code Playgroud)
请指导我如何解决它?
我的布局中有一个微调器,并使用android:prompt="@string/year"
.
默认提示如下所示:
现在我的问题是:
我的自定义适配器类
private class MyCustomSpinnerAdapter extends ArrayAdapter<ArrayList> {
private ArrayList<String> objectsList = new ArrayList<String>();
@SuppressWarnings("unchecked")
public MyCustomSpinnerAdapter(Context context, int textViewResourceId,
ArrayList objects) {
super(context, textViewResourceId, objects);
this.objectsList = objects;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView1(position, convertView, parent);
}
public View getCustomView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater(); …
Run Code Online (Sandbox Code Playgroud) 我正在使用下面提到的Apprtc.Follow视频通话应用程序.
当我将url更改为我的自定义服务器而不是apprtc服务器时,1分钟后视频通话将被断开.我失去了与服务器的连接.
为避免服务器丢失连接,我们需要在约30秒内定期ping服务器.
但是上面提到的AppRTC项目正在使用jar文件(autobanh.jar)来连接websocket,但是在库中,sendPing mentod是私有的,因此无法访问.
问题1 -有没有办法ping websocket服务器.
替换websocet库之后尝试 我用下面提到的库更改了websocket库
在重新放置websocket库之后,现在我可以访问sendPing方法了.但是在视频通话过程中60秒后我的连接丢失了.
平方法 -
public void sendPingMessageToServer() {
try {
WebSocketMessage.Ping ping = new WebSocketMessage.Ping();
// ping.mPayload="ping to server".getBytes();
mWebSocketWriter.sendPing(ping);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
在取消注释ping.mPayload行时,我得到BufferOverflowException.
定时器30秒
private void startConnectionCheckTimer() {
timerInstance.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
ws.sendPingMessageToServer();
} catch (Exception e) {
e.printStackTrace();
}
}
}, 0, 30 * 1000);
}
Run Code Online (Sandbox Code Playgroud)
请建议60秒后如何避免断电.
我有一个带有 3 个菜单选项(主页、服务等)的底部导航。主页选项卡片段包含 TabLayout 和 ViewPager。
ViewPager 有 2 个片段 - CurrentDetailFargment 和 PreviousDetailFragment。
ViewPager 有效,之后当我使用 findNavController() 应用单击 CurrentDetailFargment 按钮时,我得到异常。
导航付款屏幕
findNavController().
navigate(R.id.action_currentBillFragment_to_paymentOptionsFragment)
Run Code Online (Sandbox Code Playgroud)
例外
java.lang.IllegalArgumentException: navigation destination XXXXXXX:id/action_currentBillFragment_to_paymentOptionsFragment is unknown to this NavController
at androidx.navigation.NavController.navigate(NavController.java:789)
at androidx.navigation.NavController.navigate(NavController.java:730)
at androidx.navigation.NavController.navigate(NavController.java:716)
at androidx.navigation.NavController.navigate(NavController.java:704)
at com.bses_yamuna.user.home.currentbill.view.CurrentBillFragment.navigateToPayNow
Run Code Online (Sandbox Code Playgroud)
根据例外情况- 我没有在我的图表中提到 'action_currentBillFragment_to_paymentOptionsFragment' id。但我已经声明了它的图形。此图与 BottomNaviagtion 一起使用。
请让我知道我解决了这个问题。
活动布局部分-
<fragment
android:id="@+id/navigationHost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigation"
app:layout_constraintTop_toBottomOf="@+id/constraint_top"
app:navGraph="@navigation/menu_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
style="@style/Widget.BottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemIconTint="@drawable/bottom_navigation_item_colors"
app:itemTextColor="@drawable/bottom_navigation_item_colors"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu_modify" />
Run Code Online (Sandbox Code Playgroud)
适配器
class ViewPagerAdapter …
Run Code Online (Sandbox Code Playgroud) 我想将推文发布给以下用户身份验证用户.使用Twitter-4j库进行身份验证.我已获得以下用户的列表(姓名和ID)但无法在没有打开对话框的情况下发布推文.我正在使用此链接进行身份验证
问题 - 如何直接发布推文给Android中的身份验证用户的以下用户wihout打开Tweet对话框(消息对话框)
1.在twitterButton上单击一个使用webview打开的新活动
twitterButton=(Button) findViewById(R.id.twitter);
twitterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mTwitter = new TwitterFactory().getInstance();
mRequestToken = null;
mTwitter.setOAuthConsumer(TwitterConstants.CONSUMER_KEY,
TwitterConstants.CONSUMER_SECRET);
String callbackURL = getResources().getString(
R.string.twitter_callback);
try {
mRequestToken = mTwitter.getOAuthRequestToken(callbackURL);
System.out.println("URL"
+ mRequestToken.getAuthenticationURL());
} catch (TwitterException e) {
e.printStackTrace();
}
Intent i = new Intent(MMSExampleActivity.this,
TwitterScreen.class);
i.putExtra("URL", mRequestToken.getAuthenticationURL());
System.out.println("Url ==== "
+ mRequestToken.getAuthenticationURL());
startActivityForResult(i, TWITTER_AUTH);
}
});
Run Code Online (Sandbox Code Playgroud)
2.在onActivityResult(int requestCode,int resultCode,Intent data)方法中
if (resultCode == Activity.RESULT_OK) {
String …
Run Code Online (Sandbox Code Playgroud) 我想在android中计算一个表的行.我使用了2种方法但没有成功并获得警告消息
Launch timeout has expired, giving up wake lock!
Activity idle timeout for HistoryRecord{44e26a30 com.india.screen/.CategoryList}
Run Code Online (Sandbox Code Playgroud)
我试过了-
String query="Select count(*) from Holyplace_Tbl";
Run Code Online (Sandbox Code Playgroud)
使用rawQuery
public void countRows(String query){
Cursor mcursor = assetDatabaseHelper.executeQuery(query);
mcursor.moveToFirst();
int icount = mcursor.getInt(0);
System.out.println("NUMBER IN DB: " + icount);
mcursor.close();
Run Code Online (Sandbox Code Playgroud)
}
使用DatabaseUtils
public int countRows(String query)
{
int sometotal = (int) DatabaseUtils.longForQuery(sqliteDatabaseObj, query, null);
return sometotal;
}
Run Code Online (Sandbox Code Playgroud)
我需要创建一个包含全屏视频的列表。我使用 PagerSnapHelper 作为全屏子项目。我有一个 Exoplayer 实例并在滚动时更改视频。视频也会在水平滚动时发生变化。
RecyclerView.OnScrollListener() 方法也在水平滚动时调用。
请建议我如何解决这些问题。
1. 滚动监听器
class SnapOnScrollListener(
private val snapHelper: SnapHelper,
var behavior: Behavior = Behavior.NOTIFY_ON_SCROLL,
var onSnapPositionChangeListener: OnSnapPositionChangeListener? = null
) : RecyclerView.OnScrollListener() {
enum class Behavior {
NOTIFY_ON_SCROLL,
NOTIFY_ON_SCROLL_STATE_IDLE
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
System.out.println("dx.. $dx dy $dy")
if (behavior == Behavior.NOTIFY_ON_SCROLL) {
maybeNotifySnapPositionChange(recyclerView)
System.out.println("dx.. $dx dy $dy snapChange")
}
}
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
System.out.println("dx......")
if ( behavior == Behavior.NOTIFY_ON_SCROLL_STATE_IDLE …
Run Code Online (Sandbox Code Playgroud) android ×9
apprtc ×1
kotlin ×1
localization ×1
navigation ×1
sqlite ×1
twitter ×1
websocket ×1