Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中将包传递给RemoteView?_Android_Views_Package - Fatal编程技术网

如何在Android中将包传递给RemoteView?

如何在Android中将包传递给RemoteView?,android,views,package,Android,Views,Package,我做“edu.sju.BlackJack”并不会导致以后调用的更新发生。 我正确地引用了布局,并且应该更新布局的调用是正确的,那么我应该为包名添加什么呢 我应该补充的是,根据清单,我的包名如上所示。 这是我现在拥有的代码,它当前没有更新屏幕(或者我猜是正确地更改了值) RemoteView名称=新的RemoteView(“edu.sju.BlackJack”、R.layout.play_屏幕) 如果不是这样的话。。那么会是这个代码吗 名称。setTextViewText(R.id.Dealer_

我做“edu.sju.BlackJack”并不会导致以后调用的更新发生。 我正确地引用了布局,并且应该更新布局的调用是正确的,那么我应该为包名添加什么呢

我应该补充的是,根据清单,我的包名如上所示。 这是我现在拥有的代码,它当前没有更新屏幕(或者我猜是正确地更改了值)

RemoteView名称=新的RemoteView(“edu.sju.BlackJack”、R.layout.play_屏幕)

如果不是这样的话。。那么会是这个代码吗

名称。setTextViewText(R.id.Dealer_总计,“0”)

Dealer_Total是我要更改的文本视图的id。。然而,这种变化并没有再次发生

提前感谢您提供的一切帮助

下面是我要讲的全部代码,第一个Playscreen.java

package edu.sju.BlackJack;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import java.util.*;


public class PlayScreen extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    GameEngine Engine = new GameEngine();
     @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play_screen);
        TextView TextDealer =  (TextView)findViewById(R.id.Dealer_Total); 
        Engine.setView(TextDealer);
        //Set up click listeners for all the buttons
        View hitButton = findViewById(R.id.hit_button);
        hitButton.setOnClickListener(this);
        View standButton = findViewById(R.id.stand_button);
        standButton.setOnClickListener(this);
        //new preplay button (ML 10/24/10)
        View prePlayButton = findViewById(R.id.prePlay_button);
        prePlayButton.setOnClickListener(this);
        Thread thread = new Thread(Engine);
        thread.start();


    }   

    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.prePlay_button:
                v.setVisibility(View.GONE);
                System.out.println("Working?");
                Engine.setGameStart(1);
                break;
            case R.id.hit_button:
                Engine.gameHit(1);
                break;
            case R.id.stand_button:
                Engine.gameStand(1);
                break;
        }

            // More buttons go here (if any) ...    
        }
}

现在是游戏引擎线程 不是全部,只是足够让你明白


包edu.sju.BlackJack;
导入java.util.Random;
导入android.widget.remoteview;
导入android.widget.TextView;
公共类GameEngine实现了Runnable{
static int playerCount=0;//记录选择hit时要为玩家更换的牌
static int dealerCount=0;//记录当庄家点击时要为庄家更换哪些卡
静态int win=0;//保存wins记录(JV 10/01/10)
静态int lose=0;//保存损失记录(JV 10/01/10)
static int hit=0;//让引擎知道是否选中了hit按钮(0表示未选中)
static int stand=0;//让引擎知道是否选择了stand按钮(0表示未选择)
静态int playerTotal=0;//告诉玩家的总数(JV 10/01/10)
静态int dealerTotal=0;//告诉经销商的总数(JV 10/01/10)
static int playerTurn=0;//激活按钮,以便在单击时执行操作(当玩家转向时)
static int startGame=0;//按下开始游戏按钮时开始游戏
TextView TextDealer;
RemoteView名称=新的RemoteView(“edu.sju.BlackJack”、R.layout.play_屏幕);
公开募捐{
名称。setTextViewText(R.id.Dealer_总计,“0”);
//main();
}
公共无效设置视图(文本视图a)
{
text经销商=a;
}
公共void setGameStart(int i)
{
startGame=i;
}
公共无效游戏命中率(int i)
{
如果(playerTurn==1)
命中率=1;
}
公共游戏机台(int i)
{
如果(playerTurn==1)
站=1;
}
公共图书馆
{//开始游戏
甲板主甲板=新甲板();
填充甲板(主甲板);
//TextView TextPlayer=(TextView)findViewById(R.id.Player\u总计);
//textdaler.setText(“+dealerTotal”);
//TextPlayer.setText(“+playerTotal”);
while(true)
{
if(startGame==1)
{
if(mainDeck.getList().size()<15){
主甲板=清空甲板();
填充甲板(主甲板);
}  
//将卡视图重置为默认值
//将DealCard和PLAYERCARD总计重置为0
dealerTotal=0;
playerTotal=0;
playerCount=0;
dealerCount=0;
//游戏手(主甲板);
}
}
}

无论您的问题是什么,我不认为这是您所认为的。如果您的布局出现在应用程序小部件中,则程序包名称得到了正确处理。如果更新(您的
setTextViewText()
调用)没有效果,则
R.layout.play\u屏幕
没有
R.id.Dealer\u总计
,或者您没有发送包含
setTextViewText()的
remoteview
说明。

如果您不知道,请投票表决,我真的需要尽快回答。再次提前感谢等待,小部件是否必须使用远程视图?(我的playscreen.java类只包含布局,但本身不是“小部件”)。这也是显示屏幕和调用线程游戏引擎需要更改的内容。我真的很讨厌自动进入…R.layout.play_屏幕包含R.id.Dealer_全屏(Eclipse访问我的所有视图,并在我放置setTextViewText()时将其作为选项提供给我,因此它似乎可以很好地访问布局)…我只有RemoteViews的名称,这也是我“发送”的唯一内容所以我也不相信是这样。@John V:对不起,到目前为止,我只在应用程序小部件的上下文中使用了RemoteView。除了让游戏引擎直接接收视图并捕获抛出的异常并忽略错误/AndroidRuntime(653)之外,还有其他方法可以从游戏引擎编辑我的视图吗:android.view.ViewRoot$calledFromErrorThreadException:只有创建视图层次结构的原始线程才能接触其视图。@John V:使用
AsyncTask
、或
处理程序
、或
runOnUiThread()
post()
远程视图不适用于正常应用程序。
package edu.sju.BlackJack;

import java.util.Random;

import android.widget.RemoteViews;
import android.widget.TextView;

public class GameEngine   implements Runnable {
    static int playerCount = 0;    //keep record of which cards to change for player when hit is selected
    static int dealerCount = 0;    //keep record of which cards to change for dealer when dealer hits
    static int win = 0;     //keeps record of wins  (JV 10/01/10)
    static int lose = 0;    //keeps record of loss  (JV 10/01/10)
    static int hit = 0;     //let's engine know if hit button was selected (0 means it has not)
    static int stand = 0;    //let's engine know if stand button was selected (0 means it has not)
    static int playerTotal = 0; //tells player's total (JV 10/01/10)
    static int dealerTotal = 0; //tells dealer's total (JV 10/01/10)
    static int playerTurn = 0;  //activates buttons so that they do actions when clicked (as it's players turn)
    static int startGame = 0; //starts the game when the start game button is pressed
    TextView TextDealer;
    RemoteViews name = new RemoteViews("edu.sju.BlackJack", R.layout.play_screen);


public void run() {
    name.setTextViewText(R.id.Dealer_Total, "0");
    //main();
}

public void setView(TextView a)
{
TextDealer = a;
}

public void setGameStart(int i)
{
    startGame = i;
}

public void gameHit(int i)
{
    if(playerTurn == 1)
    hit = 1;
}

public void gameStand(int i)
{
    if(playerTurn == 1)
    stand = 1;
}


public void main()

    {//Start Game
        Deck mainDeck = new Deck();
        fillDeck(mainDeck);

        //TextView TextPlayer =  (TextView)findViewById(R.id.Player_Total); 
        //TextDealer.setText("" + dealerTotal);
        //TextPlayer.setText("" + playerTotal);

        while(true)
        {
            if(startGame == 1)
            {

                if(mainDeck.getList().size() < 15){
                    mainDeck = emptyDeck();
                    fillDeck(mainDeck);
                    }  

                //RESET CARD VIEWS TO DEFAULT
                //RESET DEALERCARD AND PLAYERCARD TOTALS TO 0
                dealerTotal = 0;
                playerTotal = 0;
                playerCount = 0;
                dealerCount = 0;

                //playHand(mainDeck);

            }
        }

    }