我试着去的设置OnDragListener到某些词TextView使用SpannableString.我可以使用添加一个OnClick监听器ClickableSpan
通过做
hashText.setSpan(new ClickableSpan() {
Run Code Online (Sandbox Code Playgroud)
所以我想我会尝试相同但替换ClickableSpan为OnDragListener.
我能够读取不同的拖动事件,但是我无法将拖动事件与我选择的特定单词隔离开来,就像我能够做到的那样ClickableSpan.
hashText.setSpan(new View.OnDragListener() {
@Override
public boolean onDrag(View targetView, DragEvent event) {
int action = event.getAction();
TextView targetVariable = (TextView) targetView;
String textGetter;
textGetter = targetVariable.getText().toString();
// boolean actionDropOutside = (DragEvent.ACTION_DRAG_ENDED != DragEvent.ACTION_DROP);
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
Log.d(TAG, "DRAG STARTED");
break;
case DragEvent.ACTION_DRAG_ENTERED:
////create method that checks if text is empty if so lights up
//if (textGetter.equals("")) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试将用户在下面的登录屏幕中输入的名称保存Settings.java到a sharedPreference,这TestFragment2.java将从另一个FragmentActivity调用,SampleTabsDefault.java
Settings.java
private void savePrefs(String key, boolean value) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
Editor edit = sp.edit();
edit.putBoolean(key, value);
edit.commit();
}
private void savePrefs(String key, String value) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
Editor edit = sp.edit();
edit.putString(key, value);
edit.commit();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
savePrefs("CHECKBOX", cb.isChecked());
if (cb.isChecked())
savePrefs("NAME", et.getText().toString());
Intent myIntent = new Intent("com.test.SAMPLETABSDEFAULT");
startActivity(myIntent);
finish();
}
}
Run Code Online (Sandbox Code Playgroud)
Intent myIntent = new Intent("com.test.SAMPLETABSDEFAULT");startActivity(myIntent);
加载SampleTabsDefault.java …
如果由于用户不说话而在RecognizerIntent完成的情况下如何处理图像(ImageView)的可见性
if (RecognizerIntent.EXTRA_RESULTS == null){
image1.setVisibility(View.VISIBLE);///microphone icon
}
Run Code Online (Sandbox Code Playgroud)
要么
if (RecognizerIntent.ACTION_RECOGNIZE_SPEECH == null){
image1.setVisibility(View.INVISIBLE);///microphone
}
Run Code Online (Sandbox Code Playgroud)
日Thnx
我已成功按照本教程https://www.youtube.com/watch?v=kFtxo7rr2HQ学习如何使用 Android Studio 构建 NDK 应用程序。
该教程使用了public native String HelloJNI();
HelloJNI.c该字符串在文件中设置
#include "com_example_myapplication_MainActivity.h"
/* Header for class com_example_myapplication_MainActivity */
/*
* Class: com_example_myapplication_MainActivity
* Method: HelloJNI
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_example_myapplication_MainActivity_HelloJNI
(JNIEnv *env, jobject obj)
{
(*env)->NewStringUTF(env, "Hello from jni");
}
Run Code Online (Sandbox Code Playgroud)
并在运行时加载
static{
System.loadLibrary("HelloJNI");
}
Run Code Online (Sandbox Code Playgroud)
现在我试图做同样的事情,但检索而int不是string
public native int getintONE();
我按照教程中的相同步骤操作,一切正常,现在我的getintONE.c阅读
#include "com_example_myapplication_MainActivity.h"
/*
* Class: com_example_myapplication_MainActivity
* Method: getintONE
* Signature: ()I
*/
JNIEXPORT jint JNICALL com_example_myapplication_MainActivity_getintONE …Run Code Online (Sandbox Code Playgroud)