2011-05-09 22 views
0

我想通過資源創建一個listview,每個打開條碼掃描器(使用android集成)並返回結果,而不顯示和發送將數據結果發送到網絡服務器(順便說一句,我成功地將數據作爲文本文件發送到網絡服務器,並希望知道如何從條形碼中獲取數據而不顯示並將數據結果作爲文本文件發送到網絡服務器) 。我在嘗試在這一步取得成功時遇到了問題。 (機器人1.5設備,項目是2.2與SDK 3使用eclipse)創建列表視圖和意圖條碼掃描器和返回結果,而不顯示並將結果數據發送到網絡服務器

string.xml 
<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<string name="hello">Hello World, MainActivity!</string> 
<string name="app_name">company</string> 
<string-array name="customer_service_group"> 
<item>Start Trip</item> 
<item>Clock In</item> 
<item>Customer Svc</item> 
<item>Independent Inspection</item> 
<item>Pick Up</item> 
<item>Log Out</item> 
</string-array> 
</resources> 

MainActivity.java 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class MainActivity extends Activity { 

    String[]Customer; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     String[] Customer = getResources().getStringArray(R.array.customer_service_group); 
     setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, Customer)); 

     ListView lv = getListView(); 
     lv.setTextFilterEnabled(true); 

     lv.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      // When clicked, show a toast with the TextView text 
      Intent i = new Intent("com.merrill.IntentIntegrator"); 
      startActivityForResult(i, 1); 
      } 

     });} 

    public void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
     if (requestCode == request_Code) { 
      if (resultCode == RESULT_OK) { 
       ------not sure what to put here----- 
    } 
     } 
    } 
} 
+0

我忘了提及的錯誤是setListAdapter,list_item和getListView。我不知道爲什麼有一個錯誤,即使進口 – merrill 2011-05-09 22:18:34

+0

有人可以幫助我嗎? – merrill 2011-05-12 22:31:38

回答

0

下面是應該開始接收來自BarcodeScanner意圖結果一些示例代碼:

/*Here is where we come back after the Barcode Scanner is done*/ 
public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
    if (requestCode == 0) { 
     if (resultCode == RESULT_OK) { 
      // contents contains whatever the code was 
      String contents = intent.getStringExtra("SCAN_RESULT"); 

      // Format contains the type of code i.e. UPC, EAN, QRCode etc... 
      String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); 

      // Handle successful scan. In this example I just put the results into the TextView 
      resultsTxt.setText(format + "\n" + contents); 
     } else if (resultCode == RESULT_CANCELED) { 
      // Handle cancel. If the user presses 'back' before a code is scanned. 
      resultsTxt.setText("Canceled"); 
     } 
    } 
} 

編輯:代替該線

resultsTxt.setText(format + "\n" + contents); 

更改它將內容發送到您的服務器。如果你有一個方法設置爲與你的服務器交互,那麼它會像

sendDataToServer(contents); 
+0

謝謝!我實際上忘記了用這個示例更新我的代碼,仍然在尋找一種不顯示結果數據並自動將數據發送到Web服務器的方法。 – merrill 2011-05-09 23:00:32

+0

已掃描的數據可以在變量內容中找到。您只需將該字符串發送到您的服務器。請參閱我的編輯,瞭解您可以設置的一種可能方式。 Tim再次感謝 – FoamyGuy 2011-05-10 13:07:12

+0

。你能檢查我的代碼,我可能會丟失什麼?由於存在多個錯誤,我無法編譯它。我仍然試圖找出如何讓它運行。 – merrill 2011-05-10 14:32:49

相關問題