小编And*_*oid的帖子

Android如何将toExtra放入TabHost活动的活动中?

从一个活动向另一个活动发送额外费用我有一点问题.我已经说过FirstActivity哪个开始TabActivity,我有5个标签.当我发送putExtra(),从,FirstActivityTabActivity,没有问题,但我需要发送额外的Activity,它持有的第一个标签TabHost.我正在使用此代码:

TabActivity.class:

int collId = getIntent().getIntExtra("collection_id", 0);
Log.i("Collection ID","Collection ID from SingleCollection.class : "+collId);

intent = new Intent(this, Collection.class);
intent.putExtra("collection_id", collId);

spec = tabHost.newTabSpec("collection").setIndicator("Collection",
                  res.getDrawable(R.drawable.ic_tab_collection))
              .setContent(intent);
tabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)

但它并没有真正起作用.我没有收到额外费用Collection.class.

所以我的问题是如何将额外内容发送到标签的内容中TabHost.希望你能理解我...

android android-tabhost android-activity

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

Android如何在JSONObject中获取int类型

我有一个放入intJSON 的问题.我有一个整数,我需要保存服务器返回给我的错误代码.问题是我必须解析它JSONObject,但JSONObject只接受字符串,而不是整数.这是我正在尝试做的一个例子:

int errorCode;
JSONObject ErrorCode;
ErrorCode = new JSONObject(errorCode);
Run Code Online (Sandbox Code Playgroud)

有什么建议如何解决这个问题?

java android json integer

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

适用于Android 2.1的Android Base64解码

我正在使用API​​ Level 7(Android 2.1)构建应用程序,我需要解码由服务器接收的字符串,该字符串使用Base64编码.我知道Base64库包含在Android 2.2中,这就是为什么我直接在我的项目中包含它的源代码.你可以在这里找到源代码:Base64.

所以我的问题是,当我尝试解码字符串中的Base64返回此:BASE 64 : [B@46392d10.

如果我运行服务器发送给我的在线base64解码器的代码我得到这个: le":"en_US","id":2,"error_code":6003,"error_string":"Unsupported Client Version"}

这是我正在使用的代码:

HttpResponse response = httpclient.execute(httppost);
Log.v("Response ","Status line : "+ response.getStatusLine().toString());
String responseBody = EntityUtils.toString(response.getEntity()); //response
Log.v("Response ","Response : "+ responseBody);

String objectIdentificator = responseBody.substring(0,32);
Log.v("Response ","Object Identificator (LONGINT) : "+ objectIdentificator);

String type = responseBody.substring(33,36);
Log.v("Response ","TYPE (UNSIGNED BYTE) : "+ type);

String operation = responseBody.substring(37,40);
Log.v("Response ","OPERATION (UNSIGNED BYTE) : "+ operation);

String objectId = responseBody.substring(41, 73);
Log.v("Response ","UID (CHAR, length …
Run Code Online (Sandbox Code Playgroud)

java base64 android

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

Android无法绑定到服务(在App-Billing中)

I'm trying to implement in app-billing in my application, but I have a little problem with it. I'm using the example from android developer's site and everytime I start the activity which will connect to the billing service it's showing me a dialog that I cannot connect to server and when I press learn more it's going to a web page which is explaining me to update my android market app, but it's already the latest one. And the other …

android in-app-purchase

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

Android从内部存储到外部存储的复制数据库

我正在尝试将现有数据库从内部存储复制到外部存储,但我有一点问题.它说the file does not exist.这是我实际使用的:

将文件从内部存储复制到外部存储:

    private void copyFile(String src, String dst) throws IOException{
    FileChannel inChannel = new FileInputStream(src).getChannel();
    FileChannel outChannel = new FileOutputStream(dst).getChannel();
    try
    {
        inChannel.transferTo(0, inChannel.size(), outChannel);
    }
    finally
    {
        if (inChannel != null)
            inChannel.close();
        if (outChannel != null)
            outChannel.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

而我正在使用它:

copyFile("/data/data/com.example.test/databases/database.sqlite","/sdcard/.Example/Data/database.sqlite");
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我很确定内部存储中的数据库是否存在.

如果我在copyFile "/sdcard/.Example/Data/"其创建文件Data中设置为目标文件夹.Example.

有什么建议我缺少什么?

database android

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

Android在imageview中对齐顶部位图

无论如何,我可以将位图对齐ImageView.我的图片视图有问题.我正在通过Java代码设置它的源代码,并且在调整位图大小后将其置于中心位置ImageView,但我想要的是对齐位图.

声明imageView:

    <RelativeLayout
    android:id="@+id/collection_background"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/actionbar" > 


     <ImageView  
        android:id="@+id/collection_image_background"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:contentDescription="@string/stampii"  />

    // countinue ........
Run Code Online (Sandbox Code Playgroud)

这是我如何设置位图:

BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inTempStorage = new byte[8*1024];

    ops = BitmapFactory.decodeStream(cis,null,o2);
    ImageView view = (ImageView) findViewById (R.id.collection_image_background);        
    view.setImageBitmap(ops);
Run Code Online (Sandbox Code Playgroud)

任何想法如何做到这一点?

android android-imageview

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

Java - Objective C - 针对每个循环问题

我正在尝试使用Objective-C(IPhone应用程序)中的一些代码在Android中构建应用程序.我正在尝试了解究竟是在做一段代码并将其转换为Java代码,但我想我需要一点点这里有帮助.首先,这里是Obj-C代码:

  (BOOL)processSqlInjectQueries:(NSArray *)injectQueries error:(NSError**)error {
    //some code

    for(NSDictionary * q in injectQueries)
                {
                    if (![q isKindOfClass:[NSDictionary class]]) continue;

                    StPacketInjectQueryPackage qType  = (StPacketInjectQueryPackage)[[q objectForKey:@"type"] intValue];
                    NSString * query = [q objectForKey:@"query"];
                }
    //some code
    }
Run Code Online (Sandbox Code Playgroud)

在Java中,我试图做这样的事情:

         // in some other method :

        JSONObject jsonData= new JSONObject();
        String authHash = jsonData.getJSONObject("client_auth_hash").toString();
        List<Map<String,String>> injectQueries= new ArrayList<Map<String,String>>();
        injectQueries.add(new HashMap<String, String>());
        //injectQueries.add(authHash);


    public boolean processSqlInjectQueries(List<Map<String,String>> injectQueries, Exception error){

        if(injectQueries==null || injectQueries.size()==0){
            boolean injectsProcessed = this.processSqlInjectQueries(injectQueries,error);
            if(!injectsProcessed){
                return false;
            }
        }

        Log.i("Info","Processing INJECT Queries...");
        boolean res …
Run Code Online (Sandbox Code Playgroud)

java foreach objective-c

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

Android插入/更新/删除SQLite查询

我正在尝试编写三种不同的方法来在Android中的SQLite数据库中插入,更新和删除数据.到目前为止,我可以在数据库中插入数据,但我无法理解如何where在SQL中添加该子句.这是我正在使用的代码:

更新方法:

public boolean updateSQL(String tableName,String key,String value){
    return updateData(tableName,key,value);
}

private static boolean updateData(String tableName,String key,String value){
    sqliteDb = instance.getWritableDatabase();
    String where = "id=?";
    ContentValues values = new ContentValues();
    values.put(key, value);
    values.put(key, value);
    sqliteDb.update(tableName, values, where, null);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

...我正在调用这样的方法:

dbHelper.updateSQL("saved_codes", "code_id", "3");
//dbHelper is an instance to a custom DatabaseHelper class.
Run Code Online (Sandbox Code Playgroud)

..和删除方法:

public boolean deleteSQL(String tableName,String key,String value){
    return deleteData(tableName,key,value);
}

private static boolean deleteData(String tableName,String key,String value) {
    sqliteDb = …
Run Code Online (Sandbox Code Playgroud)

sqlite android

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

Android ListView适配器仅显示最后一个元素

SQLite数据库中获取所有数据并显示它们时,我遇到了一些问题ListView.我正在使用的代码只显示最后一项.这是我正在使用的代码:

        ListView lv1 = (ListView) findViewById(R.id.saved_codes_listview);
        SystemDatabaseHelper systemDbHelper = new SystemDatabaseHelper(this, null, 1);
        systemDbHelper.initialize(this);

        String sqlQuery = "SELECT code_id, code_string FROM saved_codes";
        Cursor cursor = systemDbHelper.executeSQLQuery(sqlQuery);
        if(cursor.getCount()==0){
            Log.i("No Saved Codes","There is no Saved Codes.");
        } else if(cursor.getCount()>0){
            for(cursor.move(0); cursor.moveToNext(); cursor.isAfterLast()){
                String codeString = cursor.getString(cursor.getColumnIndex("code_string"));
                ArrayList<String> codes = new ArrayList<String>();
                codes.add(codeString);
                Log.i("Code String","Code String : "+codeString);
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, codes);
                lv1.setAdapter(adapter);

            }
        }
Run Code Online (Sandbox Code Playgroud)

我的数据库中有3个条目作为例子:shosho,bosho,gosho,因此我的listview中只有gosho.知道怎么解决这个问题吗?

提前致谢!

android listview

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

内部存储中的Android删除文件文件夹不起作用

我正在尝试从内部存储中删除我的文件夹,但我正在使用的代码实际上并没有工作.有什么想法吗?

Button login = (Button) findViewById(R.id.login_btn);
        login.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String name = "/data/data/"+context.getPackageName()+"/files/";
                Log.e("","path : "+name);
                File myDir = new File(name);
                myDir.delete();
                boolean iff = myDir.delete();
                Log.e("","iff : "+iff);
            }
        });
Run Code Online (Sandbox Code Playgroud)

按钮点击后得到的结果:

11-17 13:09:58.869: E/(15952): path : /data/data/com.android.test/files/
11-17 13:09:58.869: E/(15952): iff : false
Run Code Online (Sandbox Code Playgroud)

android delete-file

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