小编Sub*_*ddy的帖子

如何避免在Android的EditText中执行onTextChanged

我怎样才能避免代码行:

((EditText) findViewById(R.id.MyEditText)).setText("Hello");
Run Code Online (Sandbox Code Playgroud)

会在这里引发一个事件:

((EditText) findViewById(R.id.MyEditText)).addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
    int before, int count) {
// HERE
}

@Override
public void beforeTextChanged(CharSequence s, int start,
    int count, int after) {
}

@Override
public void afterTextChanged(Editable s) {
}
});
Run Code Online (Sandbox Code Playgroud)

我想知道是否有任何方法可以禁止onTextChanged的执行,因为我注意到在选择AutoCompleteTextView的下拉结果的情况下(没有执行onTextChanged!).

我不是在寻找像"如果你好无所事事"这样的解决方法......

android android-edittext

23
推荐指数
3
解决办法
2万
查看次数

EditText:以编程方式设置字符数

我有一个EditText,我想限制可以在此输入的字符数EditText,并以编程方式进行此限制,该怎么做?例如,假设我想将其限制为仅允许10个字符.

android android-intent android-layout

18
推荐指数
1
解决办法
2万
查看次数

按钮背景图像拉伸(wrap_content或dp用法)

我正在将背景图像设置为我的自定义按钮.我为我的应用程序制作了截图,并提到当我使用"wrap_content"作为按钮的宽度和高度时,按钮被拉伸.当我在dp中修改大小时,它会显得很好(例如:在我的mdpi文件夹中,我有48x48px图标,所以我把48dp放在宽度和高度上).你能解释一下为什么吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/definition_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp"
android:layout_alignParentTop="true" >

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/buttons"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp" >

    <Button
        android:id="@+id/addToFavorites"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/favorites_button" />

    <Button
        android:id="@+id/fontup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/fontup_button" />

    <Button
        android:id="@+id/fontdown"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/fontdown_button" />

    <Button
        android:id="@+id/comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/comment_button" />

    <Button
        android:id="@+id/speak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/speak_button" />
    </LinearLayout>

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_below="@id/buttons">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <WebView
        android:id="@+id/webView1"
        android:layout_below="@id/image_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>
    </ScrollView>

    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

上面的代码显示了我的XML文件.您可以查看此链接以查看我的问题的屏幕截图: …

android button background-image android-linearlayout

10
推荐指数
3
解决办法
2万
查看次数

如何将图像转换为base64字符串

我想将图像转换为base 64 encode to string.从那里发送到oma_status-iconxml格式的服务器.

但我从服务器响应中得到不受支持的编码....

有没有其他方法将图像转换为base64字符串?

plz..help ...

我的代码是:

        Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),  R.drawable.image);

        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 100, bao);
        byte [] ba = bao.toByteArray();

         String ba1=Base64.encodeBytes(ba);
Run Code Online (Sandbox Code Playgroud)

xml base64 encoding android encode

8
推荐指数
1
解决办法
2万
查看次数

如何使用android.util.log将日志存储在txt文件中

我知道这个话题已被讨论很多但不是这个含义.我需要将日志存储在.txt文件中,但我不能使用log4j或任何其他类,但android.util.log我有这个解决方案,但它不是最好的.具有与以下相同的信息:Log.i(TAG,"一个信息消息"); 我要写...

ERROR = logLevel < 3;
WARNING = logLevel < 2;
INFO = logLevel < 1;
if (INFO){ 

    appendLog("LEVEL: I    TIME: "+java.util.GregorianCalendar.DAY_OF_MONTH +
                        "-"+ java.util.GregorianCalendar.MONTH +" "+GregorianCalendar.HOUR_OF_DAY +":"+GregorianCalendar.MINUTE +
                        ":"+GregorianCalendar.SECOND +"."+GregorianCalendar.MILLISECOND + "    PID: "+
                        android.os.Process.myPid()+ "    TID: "+android.os.Process.myTid()+ "    Application: com.example.myapplication"+
                        "    TAG:" +TAG+ "    TEXT: An INFO Message");
}
Run Code Online (Sandbox Code Playgroud)

然后...

public void appendLog(String text) {        
    File logFile = new File("sdcard/log.txt"); 
    if (!logFile.exists()) { 
        try { 
            logFile.createNewFile(); 
        }catch (IOException e){ 
            e.printStackTrace(); 
      } 
   } 
   try { 
       BufferedWriter buf = …
Run Code Online (Sandbox Code Playgroud)

logging android file

8
推荐指数
2
解决办法
2万
查看次数

MediaRecorder以纵向模式捕获视频

我正在尝试制作自定义视频应用.我只使用清单2.2中的设置(API 8).

一切顺利,但我不明白为什么肖像模式视频与lanscape视频没有区别.

为了检测设备改变的方向,我在surfaceChanged()中使用此代码

        if (mCamera != null) {

        Camera.Parameters p = mCamera.getParameters();

        try {
            mCamera.stopPreview();
        } catch (Exception e) {
            // TODO: handle exception
        }

        int previewWidth = 0;
        int previewHeight = 0;

        if (mPreviewSize != null) {
            Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            int rotation = display.getRotation();

            switch (rotation) {
            case Surface.ROTATION_0:
                previewWidth = mPreviewSize.height;
                previewHeight = mPreviewSize.width;
                mCamera.setDisplayOrientation(90);
                break;

            case Surface.ROTATION_90:
                previewWidth = mPreviewSize.width;
                previewHeight = mPreviewSize.height;
                mCamera.setDisplayOrientation(0);
                break;

            case Surface.ROTATION_180:
                previewWidth = mPreviewSize.height;
                previewHeight …
Run Code Online (Sandbox Code Playgroud)

video android orientation mediarecorder

7
推荐指数
2
解决办法
1万
查看次数

Android碎片内容视图尚未创建

一切都运行良好.但经过我的应用程序的一些测试后.它崩溃了,在我的Logcat中我看到这个"内容视图尚未创建"经过一些谷歌搜索,我发现我应该将我的listadapter放入onActivityCreated.我的代码有点不同,我使用的是lazyadapter,所以我觉得我需要一些建议.请帮我.

public class AndroidFragment extends SherlockListFragment  implements        ActionBar.TabListener{

            static final String URL = "https://xml.xml";
            static final String KEY_SONG = "song";
            static final String KEY_ID = "id";
            static final String KEY_TITLE = "title";
            static final String KEY_CAT_ARTIST = "artistcat";
            static final String KEY_DURATION = "duration";
            static final String KEY_THUMB_URL = "thumb_url";
            static final String KEY_BIG_URL = "big_url";
            static final String KEY_CAT_URL = "cat_url";
            static final String KEY_DESC = "cat_desc";
            ArrayList<HashMap<String, String>> menuItems;
            ListAdapter adapter;
            Context appContext;

            @Override
            public View onCreateView(LayoutInflater inflater, …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

6
推荐指数
1
解决办法
5634
查看次数

如何在android中以编程方式更改app小部件中的图像

我设计了一个Android应用程序小部件,其中两个ImageView我想要更改图像ImageView时单击图像以及调用方法.现在我用RemoteView 这个

RemoteViews views1 = new RemoteViews(context.getPackageName(),
                R.layout.activity_main);
        views1.setOnClickPendingIntent(R.id.smsImageView, pendIntent1);
        appWidgetManager.updateAppWidget(appWidgetIds, views1);
Run Code Online (Sandbox Code Playgroud)

但我不知道我如何改变imageView 谢谢你的形象.

android android-widget remoteview

5
推荐指数
1
解决办法
1万
查看次数

EditText onClick不显示虚拟键盘

如果我点击我的EditText,虚拟键盘就不会显示出来了.显示光标,但没有键入键盘.

我甚至尝试手动打开但没有作品.

这是我的代码:

public class CreateNote extends Activity {
EditText titleEdit;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.createnote);
    titleEdit = (EditText) findViewById(R.id.titleEdit);
    titleEdit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            InputMethodManager imm = (InputMethodManager) CreateNote.this
                    .getSystemService(Service.INPUT_METHOD_SERVICE);
            imm.showSoftInput(titleEdit, 0);
        }
    });
    }
   }
Run Code Online (Sandbox Code Playgroud)

布局片段:

 <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#989898" >

    <EditText
        android:id="@+id/titleEdit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edittextdrawale"
        android:ems="10"
        android:textColor="#fff"
        android:textColorHint="#fff" >

        <requestFocus />
    </EditText>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

玩隐藏和寻找我的虚拟键盘的原因是什么?我在真实设备上测试,而不是在模拟器上测试.

android android-edittext android-virtual-keyboard

5
推荐指数
1
解决办法
7608
查看次数

使用硬件加速的Android MediaCodec解码器在本机代码中访问冲突

我的目标是使用Android MediaCodec解码视频流,然后使用输出图像在本机代码中进行进一步的图像处理.

平台:华硕tf700t android 4.1.1.测试流:H.264全高清@ 24 frm/s

有了Tegra-3 SoC,我依靠硬件支持视频解码.在功能上,我的应用程序表现得如预期的那样:我确实可以访问解码器图像并正确处理它们.但是,我遇到了非常高的解码器CPU负载.

在以下实验中,过程/线程负载由adb shell中的"top -m 32 -t"测量.为了从"top"获得可靠的输出,所有4个cpu内核都通过运行一些永久循环以最低优先级循环的线程来强制激活.这通过重复执行"cat/sys/devices/system/cpu/cpu [0-3]/online"来确认.为了简单起见,只有视频解码,没有音频; 并且没有时序控制,因此解码器尽可能快地运行.

第一个实验:运行应用程序,调用JNI处理函数,但所有进一步的处理调用都被注释掉了.结果:

  • 吞吐量:25 frm/s
  • 1%加载应用程序的线程VideoDecoder
  • 24%负载的进程/系统/ bin/mediaserver的线程Binder_3

似乎解码速度受CPU限制(四核CPU的25%)......启用输出处理时,解码图像正确并且应用程序正常工作.唯一的问题:解码时cpu负载过高.

经过大量的实验,我考虑给MediaCodec一个表面来绘制它的结果.在所有其他方面,代码是相同的.结果:

  • 吞吐量55 frm/s(不错!!)
  • 2%加载应用程序的线程VideoDecoder
  • 1%加载进程/ system/bin/mediaserver的线程mediaserver

实际上,视频显示在提供的Surface上.由于几乎没有任何CPU负载,这必须是硬件加速......

如果提供Surface,de MediaCodec似乎只使用硬件加速?

到现在为止还挺好.我已经倾向于使用Surface作为解决方法(不是必需的,但在某些情况下甚至是一个很好的).但是,如果提供表面,我无法访问输出图像!结果是本机代码中的访问冲突.

这真让我困惑!我没有看到的访问限制任何想法,任何或文档中http://developer.android.com/reference/android/media/MediaCodec.html.此外,谷歌I/O演示文稿http://www.youtube.com/watch?v=RQws6vsoav8中也未提及此方向.

那么:如何使用硬件加速Android MediaCodec解码器并以原生代码访问图像?如何避免访问冲突?任何帮助都会被激活!也有任何解释或提示.

我敢肯定的MediaExtractor和MediaCodec正确使用,因为该应用程序是functionaly OK(只要我不提供表面).它仍然是非常实验性的,在todo列表上有一个很好的API设计;-)

请注意,两个实验之间的唯一区别是变量mSurface:null或"mDecoder.configure(mediaFormat,mSurface,null,0)中的实际Surface";

初始化代码:

mExtractor = new MediaExtractor();
mExtractor.setDataSource(mPath);

// Locate first video stream
for (int i = 0; i < mExtractor.getTrackCount(); i++) {
    mediaFormat = mExtractor.getTrackFormat(i);
    String mime = mediaFormat.getString(MediaFormat.KEY_MIME);
    Log.i(TAG, String.format("Stream %d/%d %s", i, mExtractor.getTrackCount(), mime));
    if (streamId …
Run Code Online (Sandbox Code Playgroud)

android access-violation native-code

5
推荐指数
1
解决办法
3111
查看次数