2012-02-21 91 views
0

嗨我有一个问题,我可以让扫描仪工作完美,它解码完美,但在displaing结果显示图像和url,但我似乎无法得到它,所以如果我点击它或按钮加载它btw我17所以如果一个简单的办法,请不要取笑只是纠正我,我只是想学习如何开发和android是最好的办法BTW我使用的是开放的索里的项目,我发现二维码扫描如何使结果网址可点击?

Java文件进行实验

/* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package com.jwetherell.quick_response_code; 

import android.view.Display; 
import android.view.WindowManager; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.ImageView; 
import android.widget.TextView; 
import com.google.zxing.BarcodeFormat; 
import com.google.zxing.WriterException; 


/** 
* Example Encoder Activity. 
* 
* @author Justin Wetherell ([email protected]) 
*/ 
public final class EncoderActivity extends Activity { 
private static final String TAG = EncoderActivity.class.getSimpleName(); 

@Override 
public void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.encoder); 

    // This assumes the view is full screen, which is a good assumption 
    WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); 
    Display display = manager.getDefaultDisplay(); 
    int width = display.getWidth(); 
    int height = display.getHeight(); 
    int smallerDimension = width < height ? width : height; 
    smallerDimension = smallerDimension * 7/8; 

    try { 
     QRCodeEncoder qrCodeEncoder = null; 
     //qrCodeEncoder = new QRCodeEncoder("AT", null, Contents.Type.TEXT, BarcodeFormat.CODABAR.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("HI", null, Contents.Type.TEXT, BarcodeFormat.CODE_39.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.CODE_128.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("1234567891011", null, Contents.Type.TEXT, BarcodeFormat.EAN_13.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("12345678", null, Contents.Type.TEXT, BarcodeFormat.EAN_8.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("1234", null, Contents.Type.TEXT, BarcodeFormat.ITF.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("2345", null, Contents.Type.TEXT, BarcodeFormat.PDF_417.toString(), smallerDimension); 
     qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); 
     //qrCodeEncoder = new QRCodeEncoder("12345678910", null, Contents.Type.TEXT, BarcodeFormat.UPC_A.toString(), smallerDimension);` 
    Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); 
    ImageView view = (ImageView) findViewById(R.id.image_view); 
    view.setImageBitmap(bitmap); 

    TextView contents = (TextView) findViewById(R.id.contents_text_view); 
    contents.setText(qrCodeEncoder.getDisplayContents()); 
    setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle()); 
} catch (WriterException e) { 
    Log.e(TAG, "Could not encode barcode", e); 
} catch (IllegalArgumentException e) { 
    Log.e(TAG, "Could not encode barcode", e); 
} 

} }

Xml文件

 <?xml version="1.0" encoding="UTF-8"?> 
<!-- 
Copyright (C) 2008 ZXing authors 

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
    --> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/encode_view" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:fillViewport="true" 
       android:background="@color/encode_view" 
       android:orientation="vertical" 
       android:gravity="center"> 

    <ImageView android:id="@+id/image_view" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:scaleType="center"/> 

    <ScrollView android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:gravity="center 

    <TextView android:id="@+id/contents_text_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:gravity="center" 
       android:textColor="@color/contents_text" 
       android:textSize="18sp" 
       android:paddingBottom="8dip" 
       android:paddingLeft="8dip" 
       android:paddingRight="8dip"/> 

    </ScrollView> 

</LinearLayout> 

感谢

+0

老兄你能不能setText? – 2012-02-22 04:46:27

回答

1

此电话为您的TextView。

TextView tv = (TextView) findViewById(R.id.text2); 
tv.setMovementMethod(LinkMovementMethod.getInstance()); 

了解Linkify类...

这是使所有的链接(URL,电话号码等)点击。