小编Bla*_*elt的帖子

Android:将int从一个活动传递到另一个活动时出错

我读我的数据库中Activity A-取回String,int,String.我传递给它Activity B并希望在3个文本字段中显示它String值正确显示,但是int给了我这个错误

01-03 15:39:48.252: E/ERROR(980): android.content.res.Resources$NotFoundException: String resource ID #0x1f4
Run Code Online (Sandbox Code Playgroud)

我的代码

活动A.

Intent myintent2 = new Intent(MoneySummaryPage.this,EnterBankDetails.class);
myintent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
myintent2.putExtra("bank", updateBank);
myintent2.putExtra("amount", updateAmt);
myintent2.putExtra("Currency", updateCur);
myintent2.putExtra("constant", "1");
startActivity(myintent2);
Run Code Online (Sandbox Code Playgroud)

活动B.

    BankName =      (EditText)findViewById(R.id.bankNameLabel);
    BalanceAmount = (EditText)findViewById(R.id.balanceLabel);
    currencySpin = (Spinner)findViewById(R.id.currencySpinner);

    constantpass = getIntent().getExtras().getString("constant");

    BankName.setText(getIntent().getExtras().getString("bank"));
    BalanceAmount.setText(getIntent().getIntExtra("amount", 0));
Run Code Online (Sandbox Code Playgroud)

BalanceAmountInteger领域,我在那里得到空白值.另外,我的第三个String是填充在Spinner中?有人能告诉我填充的代码吗?

谢谢!

android

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

isGooglePlayServicesAvailable和LocationClient

无论如何都要找到手机上是否禁用了位置服务(System -> Settings -> Location),使用GooglePlayServicesLocationClient

android google-play-services

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

从arraylist android中删除

我有一个安卓游戏,涉及一艘船射击敌人.我试图让它成为如果敌人在ammos的一定距离内,那么敌人将自己从屏幕上移开.我试图这样做,代码编译,但我不确定为什么敌人一旦被击中就不会从屏幕上移除.任何人都可以看到下面的代码有什么问题吗?谢谢

for (TopEnemy i : newTopEnemy)
{
    for (int q = 0; q < ammo.length; q++)
    {
       float xsubs = i.enemyX - ammo[q].positionX;
       float ysubs = i.enemyY - ammo[q].positionY;
       float squared = (xsubs * xsubs) + (ysubs * ysubs);
       float distance = (float)Math.sqrt(squared);
       if (distance < 10.0)
       {
          newTopEnemy.remove(q);
       }
    }
 }  
Run Code Online (Sandbox Code Playgroud)

java arraylist

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

Intent JSONObject到另一个活动

我想将JSONObject传递给下面代码中else部分中的另一个活动,这样我就可以在其他活动中使用配置文件详细信息,

public void redirectToActivity(JSONObject result, JSONObject profile){

    try {           
        String status = result.getString("status");

        if (status.equals("204")) {
            Intent intent = new Intent(this, ActivityMenu.class);
            intent.putExtra("user", "email");
            this.startActivity(intent);
        } 
        else {
            Intent intent = new Intent(this, RegisterActivity.class);
            this.startActivity(intent);
            //here I want to pass JSONObject profile to RegisterActivity
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

java android json

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

无法解析inflate(int)

所以我试图在我的活动中膨胀布局,但我不断收到此错误"无法解决方法inflate(int)"

  LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View error = layoutInflater.inflate(R.layout.error_internet_connection);
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

layout android layout-inflater

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

Android - 如何更改 SQLite 表列。(添加新列)

我正在使用 Android 的 SQLite 数据库来保存文本。我之前有 2 列,桌子是这样装的

db.execSQL("create table Storage(id integer PRIMARY KEY AUTOINCREMENT,title text,body text)");
Run Code Online (Sandbox Code Playgroud)

之后我需要添加一个新列,所以我只是在上面的代码中添加了一个新行,然后它看起来像这样

db.execSQL("create table EasyPadStorage(id integer PRIMARY KEY AUTOINCREMENT,title text,body text,color text)"); //Added a column named colors
Run Code Online (Sandbox Code Playgroud)

现在,每当我启动应用程序时,它都会抛出崩溃消息,表示我的应用程序不幸已关闭。我做了一些研究,发现了一些想法,但没有人提供帮助。我使用了以下 onUpgrade 方法

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    if (oldVersion == 1 && newVersion == 2) {
        db.execSQL("DROP TABLE IF EXISTS" + Tablename);
        db.execSQL("DROP TABLE IF EXISTS" + Tablename2);
        onCreate(db);
    }

}
Run Code Online (Sandbox Code Playgroud)

我毫不犹豫地使用 drop the table,但如果 ALTER 可以工作,请指导我如何操作。通过删除表或使用 ALTER 我只希望我的应用程序不会因为在推送更新时表中的升级而崩溃。我的数据库类之前看起来像。

public class SaveN …
Run Code Online (Sandbox Code Playgroud)

database sqlite android upgrade

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

Qt插槽未调用

我试图以这种方式连接到一个信号:

QObject::connect(myObj, SIGNAL(mySignal(std::list<MyClass*> myList)), this, SLOT(mySlot(std::list<MyClass*> myList)));
Run Code Online (Sandbox Code Playgroud)

插槽未被调用.那是错的吗?我可以用std::listsignal/slot对?

编辑:没有参数的同一对工作

class TestThread : public QThread
{
    Q_OBJECT

public:
    .....
    protected:
     virtual void run();

private:
    std::list<MyClass*> myList;

signals:
    void mySignal(std::list<MyClass*>&);



};
Q_DECLARE_METATYPE (std::list<MyClass*>)
Run Code Online (Sandbox Code Playgroud)

编辑:

void mySlot(const std::list<MyClass*> &);

void 
MyManager::mySlot(const std::list<MyClass*> &theList)
{
    std::cout << "mySlot " << std::endl;
}

void mySignal(const std::list<MyClass*> &theList);

TestThread ::TestThread (std::list<MyClass*>&theList, QObject *parent)
    :  QThread(parent),  myList(theList)
{


}



void
TestThread ::run() 
{
   ...
   emit mySignal(myList);
}
Run Code Online (Sandbox Code Playgroud)

到底:

QObject::connect(threadObj, SIGNAL(mySignal(std::list<MyClass*>)), this, SLOT(mySlot(std::list<MyClass*>)));
Run Code Online (Sandbox Code Playgroud)

qt signals-slots

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

在-90度旋转总Textview

我想在-90度设置我的textview意味着我要像这样展示它!我想在单线性布局中显示8个textviews.我能够旋转,但我只能看到一个textview.Please任何人都可以帮我一些例子.

在此输入图像描述

提前致谢.

public class AngledTextView extends TextView
{ 

       public AngledTextView(Context context, AttributeSet attrs) 
       { 
          super(context, attrs); 
       } 

       @Override 
       protected void onDraw(Canvas canvas) 
       { // Save the current matrix 
         canvas.save(); 
         // Rotate this View at its center 
         canvas.rotate(270,this.getWidth()/2, this.getHeight() /2); 
         // Draw it 
         super.onDraw(canvas); 
         // Restore to the previous matrix 
         canvas.restore(); 
        } 
 } 
Run Code Online (Sandbox Code Playgroud)

android rotation textview

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

Android布尔资源不被识别为bool,而是作为int

我正在编写一个Android应用程序,并且在定义boolean资源方面存在问题.

我有一个文件, bools.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="preferences_autoplay">true</bool>
</resources>
Run Code Online (Sandbox Code Playgroud)

然而,当我尝试使用时R.bool.preferences_autoplay,它被认为是一个int而不是一个boolean:

在此输入图像描述

我收到错误:

putBoolean(String, boolean)类型中的方法SharedPreferences.Editor不适用于参数(String, int)

int如果我需要,我当然可以使用一个,但我不明白为什么它不被认为是一个boolean.

关于如何使用boolean资源的任何想法boolean

android android-resources

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

推送通知图标Android

如何在android中的通知区域添加通知图标?我试试这个,但这会在通知区域显示一个空白空格.

mNotificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);        
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, Receive_Message_list.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this)           
        .setSmallIcon(R.drawable.pushicon)
        .setContentTitle("MAY-I")
        .setStyle(new NotificationCompat.BigTextStyle()
                .bigText(notification_message))
                .setContentText(notification_message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

notifications android push-notification android-notifications

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