2011-08-18 59 views
0

我有一個ListView顯示存儲在文件中的數據,通常我們也可以從這個ListView中刪除一行(數據)。該文件的數據存儲在另一個類中。我想在刪除它之前檢索ListView中指定行的value1(公共)變量(請參閱代碼)。我可以指定arg2行的ListView的value1嗎?檢索ListView中指定行的值

new DialogInterface.OnClickListener() { 
@Override 
public void onClick(DialogInterface dialog, 
int id) { 
Carburant m= new Carburant(); //instanciate the class that contains the value1 variable 
String value1= m.value1; //here i want to store value1 variable of arg2 line in the ListView 
list.remove(arg2); //here all the line (data) will be deleted 

謝謝你的幫助。

回答

1

listeView.getItem(index);

你可以得到的onClick索引。

+0

請舉例嗎?看來它可以解決問題:\。它檢索這一行中的所有數據:)) – androniennn

+0

您必須使用OnItemClickListener,將其設置爲您的listView.addItemClickListener(new OnItemClickListener(){void onItemClick ...})等等。這會給你點擊項目的ID。你可以調用listView.getItem(id)從listView中檢索該項目。 – bitle

+0

看看這個[示例](http://developer.android.com/resources/tutorials/views/hello-listview.html) – bitle