我正在编写一个使用NFC来读取存储在其上的数据的应用程序.我的应用程序使用Fragments和Fragment没有onNewIntent()方法.因为,我正在阅读的数据是通过处理NFC相关操作的单独类来完成的,我唯一需要做的就是更新Fragment中的TextView.但是,此实现也可用于将新Intent传递给Fragment.
这是我当前使用接口的实现.在收到新的Intent并且NFC相关检查成功后,我正在呼叫监听器.这是托管Fragment的FragmentActivity.
public class Main extends FragmentActivity implements
ActionBar.OnNavigationListener {
private Bundle myBalanceBundle;
private NFC nfcObj;
private NewBalanceListener newBlanceListener;
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
}
@Override
protected void onResume() {
getNFCState();
super.onResume();
}
private void getNFCState() {
//Other NFC related codes
else if (nfc_state == NFC.NFC_STATE_ENABLED){
readNFCTag();
}
}
private void readNFCTag() {
//Other NFC related codes
if (getIntent().getAction().equals(NfcAdapter.ACTION_TECH_DISCOVERED)) {
nfcObj.setTag((Tag) getIntent().getParcelableExtra(
NfcAdapter.EXTRA_TAG));
nfcObj.readQuickBalance();
transitQuickReadFragment(nfcObj.getCurrentBalance());
}
}
private void transitQuickReadFragment(String balance) {
// Creates a balance bundle and …Run Code Online (Sandbox Code Playgroud) 我有一个服务与以下构造函数:
public ShimmerService(Context context, Handler handler) {
mHandler = handler;
}
Run Code Online (Sandbox Code Playgroud)
我想实例化这个服务类.我有以下代码但是,我不知道在哪里通过参数:
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder) {
mShimmerService = ((ShimmerService.ShimmerConfigureBinder) binder)
.getService();
Toast.makeText(ConfigureShimmer.this,
"Shimmer service has succesfully started.",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
mShimmerService = null;
}
};
Run Code Online (Sandbox Code Playgroud)
我有其他一切设置,包括绑定,开始等等.但我在上面的代码中得到错误:
04-03 19:06:10.285: E/AndroidRuntime(16837): java.lang.RuntimeException: Unable to instantiate service com.milanix.androidecg.services.ShimmerService: java.lang.InstantiationException: can't instantiate class com.milanix.androidecg.services.ShimmerService; no empty constructor
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我需要在哪里传递参数?以下代码可以工作,但它更像是使用服务类作为类,而不是服务:
mShimmerService = new ShimmerService(this, mHandler);
Run Code Online (Sandbox Code Playgroud) 我想知道是否有人可以提供提示或来源以实现"Circle - Who's Around?"中使用的以下滑块小部件.这是我第一次遇到这个,我不确定这个小部件的确切名称:


我正在考虑使用自定义搜索栏背景来执行此操作,但我不知道如何确定搜索栏将在下一步中达到的确切像素.因为,这将独立于设备.在我的情况下,我计划使用图像,而不是指标.
请不要指向此链接http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/,因为这不是我想要实现的目标.他们似乎使用静态图像页脚来显示D,W,K.我已经尝试过那个应用程序,它甚至没有走到精确的点或D,W,K.我看过AT&T Android Slider Controls但它们似乎没有为它提供任何来源.我发现一些iOS开发者实现了这一点但是,我并不真正了解obj C代码以便在Android中实现这一点.
如果从Fragment调用,我的DialogFragment会抛出ClassCastException,而如果从Activity调用它则正常工作.我已经看过几个有类似问题的其他问题,基本上那些与导入有关,但我在实现中无法解决它.这是我对DialogFragment的实现.
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
public class HotspotScanDialog extends DialogFragment {
SetupHotspotDialogListener mListener;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
...
.setAdapter(hotspotAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mListener.onHotspotSelectedListener(hotspotAdapter.getItem(
which).toString());
}
})...
}
public interface SetupHotspotDialogListener {
public void onHotspotSelectedListener(String selection);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (SetupHotspotDialogListener) activity;
} catch (ClassCastException ignore) {
// Just to make sure if anyone will be pointing at my … 是否可以将键映射到多维数组列表.有点像下面的例子..
Map<K,V>
Run Code Online (Sandbox Code Playgroud)
其中K是字母表列表的关键,V是存储单词列表的多维数组列表或普通数组列表.有些东西就像是一个读取字典文件的应用程序.我想看一个例子.示例可以是与Map和Multi Dimensional Array-list相关的任何内容.或者还有其他有效的方法来实现收集吗?我从未使用过这样的实现,所以如果已经有一个与我的质量保证相关的帖子,请发布链接.
我的应用程序使用多播来发送信标以及协议消息和加入多播组的主机的IP.在Android设备中,它返回127.0.0.1.我环顾四周,发现有很多人建议更改主机文件.但是,在android的情况下,在我的上下文中是不可能的.如何获取设备的真实IP,而不是环回地址..
private void getLocalAddress()
{
try {
String localHost = InetAddress.getLocalHost().getHostAddress();
servers.add(localHost);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 如何使用printf格式化输出.
假设我想在格式化程序中打印以下内容.
testing testing testing testing
testingggg testingggg testingggg testingggg
Run Code Online (Sandbox Code Playgroud)
我不问有关使用"\ t",我问的是printf样式格式?如果有人可以给我建议和例子.或者可以与示例链接.我可以做到符合我的需要.