2011-12-01 40 views
0
Hits hits = indexSearcher.search(parser.parse("("+ "text:" +mEdit.getText().toString() + ")")); 
String txt2[] =new String[100]; 
String txt=""; 
for (int i = 0; i < hits.length(); i++) 
{ 
    Document hitDoc = hits.doc(i); 
    Log.i("TestAndroidLuceneActivity", "Lucene: " +hitDoc.get("title")+ hitDoc.get("path")); 
    txt=hitDoc.get("title"); 
    txt2[i]=txt;  
    final String path= hitDoc.get("path"); 
    lv.setAdapter(new ArrayAdapter<String>(Lucenconcept.this,android.R.layout.simple_list_item_1 ,txt2)); 
} 

lv.setOnItemClickListener(new OnItemClickListener() { 
    @Override 

    public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) { 
     Intent intent = new Intent(Lucenconcept.this,ShowDetails.class); 
     Bundle bundle = new Bundle(); 
     bundle.putString("keyLink", path); 
     intent.putExtras(bundle); 
     startActivity(intent); 
    } 
}); 

我編寫了用於切換另一個活動但不區分URL-id或bundle中路徑ID的代碼。存儲每個網址字符串,但是當我轉到下一個活動時。如何在項目上使用urlid(路徑)切換項目select

String link = bundle.getString("keyLink"); 
Toast.makeText(this,link,Toast.LENGTH_SHORT).show(); 

代碼檢索URL-ID或路徑的下一個活動,但不會相差它給定的URL。 請幫助我,我無法設置位置。

回答

0
for (int i = 0; i < hits.length(); i++) 
{ 
    Document hitDoc = hits.doc(i); 
    Log.i("TestAndroidLuceneActivity", "Lucene: " +hitDoc.get("title")+ hitDoc.get("path")); 
    txt=hitDoc.get("title"); 
    txt2[i]=txt;  
    final String path= hitDoc.get("path"); 
    ... 
} 

從上面的代碼看來,路徑似乎包含最後一個文檔的URL;因爲您將所有值存儲在相同的路徑變量中。 要解決這個問題,你必須得到函數public void onItemClick(...)的路徑值,並且該函數包含第三個參數作爲你點擊的列表項的位置。 在功能上寫下面的代碼onItemClick(...)

Document hitDoc = hits.doc(<listItemPosition>); 
txt=hitDoc.get("title"); 
path= hitDoc.get("path"); 
Intent intent = new Intent(Lucenconcept.this,ShowDetails.class); 
Bundle bundle = new Bundle(); 
bundle.putString("keyLink", path); 
intent.putExtras(bundle); 
startActivity(intent); 
相關問題