小编B. *_*ney的帖子

如何通过换行拆分字符串?

我是Android开发的菜鸟,我试图通过多个换行符多次拆分字符串.我正在尝试拆分的字符串是从数据库查询中提取的,并且构造如下:

public String getCoin() {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_QUANTITY, KEY_OUNCES, KEY_VALUE };
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    String result = "";

    int iRow = c.getColumnIndex(KEY_ROWID);
    int iName = c.getColumnIndex(KEY_NAME);
    int iQuantity = c.getColumnIndex(KEY_QUANTITY);
    int iOunces = c.getColumnIndex(KEY_OUNCES);
    int iValue = c.getColumnIndex(KEY_VALUE);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
        result = result + /*c.getString(iRow) + " " +*/ c.getString(iName).substring(0, Math.min(18, c.getString(iName).length())) + "\n";
    }
    c.close();
    return result;
Run Code Online (Sandbox Code Playgroud)

result.getCoin读成:

alphabravocharlie
Run Code Online (Sandbox Code Playgroud)

我想在换行符处拆分字符串并将每个子字符串放入一个字符串数组中.这是我目前的代码: …

java android

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

为什么自定义视图无效?

我是Android开发的菜鸟,我遇到了使视图无效的问题.我正在使用教程,并没有实现它的问题.但是,当我更改视图的背景时,它仍然会响应,就像之前的背景仍然设置一样.换句话说,我更改了蒙版,但我的"touchview"类没有看到新的蒙版.我没有运气使用invalidate更新视图,我已经验证掩码实际上被重置为背景.任何帮助将不胜感激.

我的代码

@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId())
    {
        case 1:   // id from the xml file
            if(isMale){
                isMale=false;
                item.setIcon(R.drawable.male_icon);
                imageViewOriginal.setImageResource(R.drawable.woman_front);
                imageViewFlip.setImageResource(R.drawable.woman_back);
                if(isFrontView){
                    myMask.setBackgroundResource(R.drawable.woman_front_mask); //Mask changed here
                }else{
                    myMask.setBackgroundResource(R.drawable.woman_back_mask);  //Mask changed here
                }
            }else{
                isMale=true;
                item.setIcon(R.drawable.female_icon);
                imageViewOriginal.setImageResource(R.drawable.man_front);                   
                imageViewFlip.setImageResource(R.drawable.man_back);
                if(isFrontView){
                    myMask.setBackgroundResource(R.drawable.man_front_mask); //Mask changed here
                }else{
                    myMask.setBackgroundResource(R.drawable.man_back_mask);  //Mask changed here
                }

            }

            touchView.invalidate();
            infoView.invalidate();
            myMask.invalidate(); //Mask View Invalidated here

            return true;   // we handled the click, dont pass it up the chain

        case …
Run Code Online (Sandbox Code Playgroud)

layout android view mask invalidation

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

如何正确更新AppWidget?

我是Android的菜鸟,我在更新appwidget时遇到问题.它是一个新闻小部件,每20秒显示不同的文本.初始化窗口小部件时,我可以正确切换和显示文本.但是,在每30分钟更新一次窗口小部件之后,我的widgetID int数组会保留更新之前存在的int.因此,每次更新后,窗口小部件都会显示旧数据和新数据.是否在更新过程中清除小部件ID int旧数据数组.任何帮助是极大的赞赏.

我的代码:

allWidgetIds2 = appWidgetManager.getAppWidgetIds(thisWidget);
Run Code Online (Sandbox Code Playgroud)

在窗口小部件中切换文本的方法 这最初工作正常,但更新后显示旧数据和新数据...

   public void updateStory() {

    tickerheadline = RssReader.rssheadline.get(storyCounter);
    tickerstory = RssReader.rssstory.get(storyCounter);
    remoteViews.setTextViewText(R.id.headline, tickerheadline );
    remoteViews.setTextViewText(R.id.story, tickerstory );
    if (storyCounter==RssReader.rssheadline.size()-1){
        storyCounter = 0;
        storyCounter++;
    }else{
        storyCounter++;
    }
    appWidgetManager.updateAppWidget(allWidgetIds, remoteViews); 
    //Log.e("Widget", allWidgetIds.toString());
    mHandler.postDelayed(new Runnable() { 
         public void run() { 
           updateStory(); 
         } } ,20000);  }

}
Run Code Online (Sandbox Code Playgroud)

编辑

public void updateStory() {
    //Added
    appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());
    ComponentName thisWidget = new ComponentName(getApplicationContext(),MyWidgetProvider.class);
    remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(),R.layout.widget1);    


    tickerheadline = RssReader.rssheadline.get(storyCounter);
    tickerstory = RssReader.rssstory.get(storyCounter);
    remoteViews.setTextViewText(R.id.headline, tickerheadline );
    remoteViews.setTextViewText(R.id.story, tickerstory …
Run Code Online (Sandbox Code Playgroud)

int android updates android-widget android-appwidget

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

为什么Youtube视频没有充满UiWebView?

我是iphone开发的菜鸟,我在UIwebview中显示嵌入式YouTube视频时遇到问题.目前,youtube视频位于uiwebview的左上角,它还有一个烦人的边框.我将youtube框架设置为与我的uiwebview相同的尺寸,并将webview设置为"scale to fit".如何让我的YouTube内容适合整个屏幕并摆脱边框?任何帮助是极大的赞赏.

我的代码

NSString *video_ID = youtubeid;
NSString *htmlStr = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"320\" height=\"230\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe>",video_ID];
[videoScreen loadHTMLString:htmlStr baseURL:nil]; 
Run Code Online (Sandbox Code Playgroud)

编辑

 NSString *video_ID = youtubeid;
NSString *htmlStr = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"100%\" height=\"100%\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe>",video_ID];
[videoScreen loadHTMLString:htmlStr baseURL:nil]; 
Run Code Online (Sandbox Code Playgroud)

html youtube iphone uiwebview ios

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

如何旋转libstreaming Video Preview?

我是android开发的菜鸟 ,我正在尝试实现libstreaming 示例3示例项目.一切正常,但我无法将视频预览的方向更改为prtrait.无论我改变什么设置,它都会拒绝旋转并保持横向模式.我知道可以实现纵向方向,因为spydroid使用libstreaming并以纵向方式显示任何帮助都非常感谢.

我的相关代码:

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //<--Does Nothing

    // Configures the SessionBuilder
    mSession = SessionBuilder.getInstance()
            .setContext(getApplicationContext())
            .setAudioEncoder(SessionBuilder.AUDIO_AAC)
            .setAudioQuality(new AudioQuality(8000, 16000))
            .setVideoEncoder(SessionBuilder.VIDEO_H264)
            .setSurfaceView(mSurfaceView)
            .setPreviewOrientation(90) //<--Does Nothing
            .setCallback(this)
            .build();
Run Code Online (Sandbox Code Playgroud)

video android orientation surfaceview

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

是否可以在没有触摸的情况下与UIWebView交互?

我正在尝试与UIWebView中的加载页面进行交互而不触摸屏幕.我尝试过mediaplaybackrequiresuseraction没有成功.我也试过这里提供的方法,但显然它在ios 6中不起作用.我正在尝试加载这个 url并让播放器开始播放.有谁知道如何使这项工作ios 6?任何帮助是极大的赞赏.

我的代码

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


  int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

  NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
  //storyLink is various form of http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001 with different bctid=value

  NSURL *kitcoURL = [NSURL URLWithString:storyLink];
  NSURLRequest *requestURL = [NSURLRequest requestWithURL:kitcoURL];
  [videoScreen setUserInteractionEnabled:YES];
  [videoScreen setMediaPlaybackRequiresUserAction:NO];
  [videoScreen loadRequest:requestURL];

 }
Run Code Online (Sandbox Code Playgroud)

//方法在ios6中不起作用

 - (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;

if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}

if (view.subviews && …
Run Code Online (Sandbox Code Playgroud)

html iphone url uiwebview ios

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

如何在自定义坐标上定位自定义对话框?

我是Android开发的菜鸟,我试图弄清楚如何在视图中的特定坐标处显示NewQuickAction3D弹出对话框.我正在将弹出窗口与教程集成.本质上,我想使用弹出对话框显示用户触摸的数据,而不是使用"infoview"在画布上绘画.目前,弹出窗口显示在我将其锚定到的视图的顶部和中心.如何让它显示特定的坐标?任何帮助是极大的赞赏.

我的代码

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
     infoView.updateInfo(t_info, t_x, t_y, t_c); //Infoview paints to on a specific coordinate
     quickAction.show(infoView); //How do I use the t_x & t_y coordinates here instead of just anchoring infoview
Run Code Online (Sandbox Code Playgroud)

编辑

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
     infoView.updateInfo(t_info, t_x, t_y, t_c);
     WindowManager.LayoutParams wmlp = quickAction.getWindow().getAttributes(); //Error here getting window attributes
     wmlp.gravity = Gravity.TOP | Gravity.LEFT;
         wmlp.x = 100;   //x position
         wmlp.y = 100;   //y position …
Run Code Online (Sandbox Code Playgroud)

android dialog canvas view coordinates

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

如何暂停和恢复 For 循环?

我是 Android 新手,我正在尝试从字符串数组列表中循环文本并将它们显示在文本切换器中。我希望文本每两秒更改一次。我使用这个问题作为我的指南,并且使用按钮切换文本没有问题。但是,当我尝试使用 for 循环并延迟 2 秒来循环文本时,它仅显示 arrayList 中的第一个文本。如何让循环持续执行并暂停?任何帮助是极大的赞赏。

我的守则;

private void updateCounter()
{   

    try{
    for (int i=0; i< CoinShowReader.tickercontent.size(); i++){                             

        mHandler.postDelayed(new Runnable() { 
             public void run() { 
                m_switcher.setText((CoinShowReader.tickercontent.get(CoinShowReader.m_counter)));               
                CoinShowReader.m_counter++;
             } 
        }, 2000);

        }

    }catch(Exception e){
        e.printStackTrace();    
    }
}  
Run Code Online (Sandbox Code Playgroud)

multithreading android loops wait postdelayed

4
推荐指数
1
解决办法
2091
查看次数

如何使用AndEngine构建多层场景?

我是Android开发的菜鸟,我正在努力学习如何使用AndEngine.我想构建一个场景,其中一个精灵从前景中的一个物体后面出现,然后以一种w mole的方式消失.我已经审查了每个示例项目,但找不到任何显示如何执行此操作的代码.任何帮助是极大的赞赏.

目前,我正在尝试使用精灵来设置前景场景无济于事.

@Override
    public Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());

        final Scene scene = new Scene();
        final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
        final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
        autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(), this.mParallaxLayerBack, vertexBufferObjectManager)));
        autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid, vertexBufferObjectManager)));
        autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront, vertexBufferObjectManager)));
        scene.setBackground(autoParallaxBackground);

        final float centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
        final float centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
        final Sprite face = new Sprite(centerX, …
Run Code Online (Sandbox Code Playgroud)

android game-engine scene android-layout andengine

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

从非活动类发出启动活动

我是Android的菜鸟,我有一个也使用OverlayItems的Map Activity.在我的overlay类的onButtonTap方法中,我想执行startActivity,然后我可以使用intent.ACTION_CALL.

Intent callIntent = new Intent(Intent.ACTION_CALL);   
callIntent.setData(Uri.parse("tel:"+MapActivity.phonenumber0));
startActivity(callIntent);
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我被要求为startActivity(Intent)创建一个方法,我不明白.当我尝试......

Intent callIntent = new Intent(Intent.ACTION_CALL);   
callIntent.setData(Uri.parse("tel:"+MapActivity.phonenumber0));
MapActivity.startActivity(callIntent);
Run Code Online (Sandbox Code Playgroud)

它说我不能对非静态方法的非静态引用进行静态引用.当我尝试使用对象的上下文时,即被按下的按钮,它将不允许我这样做.

Intent callIntent = new Intent(Intent.ACTION_CALL);   
callIntent.setData(Uri.parse("tel:"+MapActivity.phonenumber0));
ContextObj.startActivity(callIntent);
Run Code Online (Sandbox Code Playgroud)

当然,将这段代码移动到主Activity需要一个静态方法,它提出了一系列问题.

如何为startActivity设置适当的上下文?任何帮助是极大的赞赏.

static android class android-intent android-activity

0
推荐指数
1
解决办法
6843
查看次数