3
我在android中使用listview。以前我曾經從數據庫中提取數據,所以我用CursorAdapter,但現在我從網站和網站獲取響應,我有不同的鏈接,每個鏈接都有它的名字與它關聯。我有兩個字符串數組中的名稱和鏈接。我只需要顯示名稱,點擊時每個名稱都會打開一個新的鏈接作爲參數。Android列表視圖與額外的額外隱藏字段
下面是我在做什麼
listView = (ListView) findViewById(R.id.list);
String[] names= new String[] { "name1",
"name2"
};
String[] links= new String[] { "link1",
"link2"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, send names and links);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String itemValue = (String) listView.getItemAtPosition(position);
Intent myIntent = new Intent(arg0.getContext(), NewPage.class);
myIntent.putExtra("Url",how to get this);
startActivity(myIntent);
}
});
}
謝謝你,我也有這個想法,但我不確定哪個變量listview會顯示,它會隱藏。這就是你爲什麼重寫toString函數嗎? – Hamza
@Hamza是的,默認情況下,ArrayAdapter會調用數據對象的'toString()'方法,並使用結果字符串在行佈局中顯示它。 – Luksprog