Android 中如何将包传递到 RemoteView?

发布于 2024-09-30 13:43:31 字数 4667 浏览 3 评论 0原文

我执行“edu.sju.BlackJack”不会导致稍后调用的更新发生。 我正确引用了布局,并且应该更新它的调用是正确的,那么我应该在包名称中输入什么?

我应该补充一点,根据清单,我的包名称是上面的。 这是我现在拥有的代码,当前不会更新屏幕(或者我猜测正确更改了值)。

RemoteViews 名称 = new RemoteViews("edu.sju.BlackJack", R.layout.play_screen);

如果不是的话..会是这段代码吗?

name.setTextViewText(R.id.Dealer_Total, "0");

Dealer_Total 是我想要更改的 TextView 的 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) ...    
        }
}

现在这是 GameEngine 线程 不是全部,只要让你明白就足够了


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);

            }
        }

    }

Me Doing "edu.sju.BlackJack" Is not causing updates that are later called to occur.
I reference the layout correctly and the calls that are supposed to update it are correct, so what do I put in for the package name?

I should add that my package name according to the manifest is the above.
This is the code I have now which currently doesn't update the screen (or i'm guessing change the value correctly).

RemoteViews name = new RemoteViews("edu.sju.BlackJack", R.layout.play_screen);

If that's not it.. would it then be this code?

name.setTextViewText(R.id.Dealer_Total, "0");

Dealer_Total is the id for the TextView that I want to change.. however again the Change is not occurring.

Thanks in advance for any and all assistance.

Here is the whole of my code that i'm talking about, first 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) ...    
        }
}

Now here's the GameEngine Thread
Not the Whole of it, just enough so you get the idea


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);

            }
        }

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2024-10-07 13:43:31

不管你的问题是什么,我认为它不是你想象的那样。如果您的布局出现在应用程序小部件中,则说明包名称已得到正确处理。如果更新(您的 setTextViewText() 调用)没有效果,则 R.layout.play_screen 没有 R.id.Dealer_Total code> 或者您没有通过包含 setTextViewText() 指令的 RemoteViews 发送。

Whatever your problem is, I don't think it is what you think it is. If your layout is appearing in the app widget, then the package name is being handled properly. If the update (your setTextViewText() call) is not having an effect, then either R.layout.play_screen does not have R.id.Dealer_Total or you are not sending over a RemoteViews that contains the setTextViewText() instructions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文